finally move buildroot-ng to trunk
[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);\r
6    int lp = remainder % 5;\r
7    int pb = remainder / 5;\r
8 -  if (pb > NLength::kNumPosStatesBitsMax)\r
9 -    return E_INVALIDARG;\r
10 -  _posStateMask = (1 << pb) - 1;\r
11    UInt32 dictionarySize = 0;\r
12    for (int i = 0; i < 4; i++)\r
13      dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);\r
14 +  return SetDecoderPropertiesRaw(lc, lp, pb, dictionarySize);\r
15 +}\r
16 +\r
17 +STDMETHODIMP CDecoder::SetDecoderPropertiesRaw(int lc, int lp, int pb, UInt32 dictionarySize)\r
18 +{\r
19 +  if (pb > NLength::kNumPosStatesBitsMax)\r
20 +    return E_INVALIDARG;\r
21 +  _posStateMask = (1 << pb) - 1;\r
22    if (!_outWindowStream.Create(dictionarySize))\r
23      return E_OUTOFMEMORY;\r
24    if (!_literalDecoder.Create(lp, lc))\r
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);\r
30  \r
31    STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);\r
32 +  STDMETHOD(SetDecoderPropertiesRaw)(int lc, int lp, int pb, UInt32 dictionarySize);\r
33  \r
34    STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);\r
35  \r
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 +/*\r
137 + * lzma zlib simplified wrapper\r
138 + *\r
139 + * Copyright (c) 2005-2006 Oleg I. Vdovikin <oleg@cs.msu.su>\r
140 + *\r
141 + * This library is free software; you can redistribute \r
142 + * it and/or modify it under the terms of the GNU Lesser \r
143 + * General Public License as published by the Free Software \r
144 + * Foundation; either version 2.1 of the License, or \r
145 + * (at your option) any later version.\r
146 + *\r
147 + * This library is distributed in the hope that it will be \r
148 + * useful, but WITHOUT ANY WARRANTY; without even the implied \r
149 + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
150 + * PURPOSE. See the GNU Lesser General Public License \r
151 + * for more details.\r
152 + *\r
153 + * You should have received a copy of the GNU Lesser General \r
154 + * Public License along with this library; if not, write to \r
155 + * the Free Software Foundation, Inc., 59 Temple Place, \r
156 + * Suite 330, Boston, MA 02111-1307 USA \r
157 + */\r
158 +\r
159 +/*\r
160 + * default values for encoder/decoder used by wrapper\r
161 + */\r
162 +\r
163 +#include <zlib.h>\r
164 +\r
165 +#define ZLIB_LC 3\r
166 +#define ZLIB_LP 0\r
167 +#define ZLIB_PB 2\r
168 +\r
169 +#ifdef WIN32\r
170 +#include <initguid.h>\r
171 +#else\r
172 +#define INITGUID\r
173 +#endif\r
174 +\r
175 +#include "../../../Common/MyWindows.h"\r
176 +#include "../LZMA/LZMADecoder.h"\r
177 +#include "../LZMA/LZMAEncoder.h"\r
178 +\r
179 +#define STG_E_SEEKERROR                  ((HRESULT)0x80030019L)\r
180 +#define STG_E_MEDIUMFULL                 ((HRESULT)0x80030070L)\r
181 +\r
182 +class CInMemoryStream: \r
183 +  public IInStream,\r
184 +  public IStreamGetSize,\r
185 +  public CMyUnknownImp\r
186 +{\r
187 +public:\r
188 +  CInMemoryStream(const Bytef *data, UInt64 size) : \r
189 +         m_data(data), m_size(size), m_offset(0) {}\r
190 +\r
191 +  virtual ~CInMemoryStream() {}\r
192 +\r
193 +  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)\r
194 +\r
195 +  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)\r
196 +  {\r
197 +         if (size > m_size - m_offset) \r
198 +                 size = m_size - m_offset;\r
199 +\r
200 +         if (size) {\r
201 +                 memcpy(data, m_data + m_offset, size);\r
202 +         }\r
203 +\r
204 +         m_offset += size;\r
205 +\r
206 +         if (processedSize) \r
207 +                 *processedSize = size;\r
208 +\r
209 +         return S_OK;\r
210 +  }\r
211 +\r
212 +  STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize)\r
213 +  {\r
214 +       return Read(data, size, processedSize);\r
215 +  }\r
216 +\r
217 +  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r
218 +  {\r
219 +         UInt64 _offset;\r
220 +\r
221 +         if (seekOrigin == STREAM_SEEK_SET) _offset = offset;\r
222 +         else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset; \r
223 +         else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;\r
224 +         else return STG_E_INVALIDFUNCTION;\r
225 +\r
226 +         if (_offset < 0 || _offset > m_size)\r
227 +                 return STG_E_SEEKERROR;\r
228 +\r
229 +         m_offset = _offset;\r
230 +\r
231 +         if (newPosition)\r
232 +                 *newPosition = m_offset;\r
233 +\r
234 +         return S_OK;\r
235 +  }\r
236 +\r
237 +  STDMETHOD(GetSize)(UInt64 *size)\r
238 +  {\r
239 +         *size = m_size;\r
240 +         return S_OK;\r
241 +  }\r
242 +protected:\r
243 +       const Bytef *m_data;\r
244 +       UInt64 m_size;\r
245 +       UInt64 m_offset;\r
246 +};\r
247 +\r
248 +class COutMemoryStream: \r
249 +  public IOutStream,\r
250 +  public CMyUnknownImp\r
251 +{\r
252 +public:\r
253 +  COutMemoryStream(Bytef *data, UInt64 maxsize) : \r
254 +         m_data(data), m_size(0), m_maxsize(maxsize), m_offset(0) {}\r
255 +  virtual ~COutMemoryStream() {}\r
256 +  \r
257 +  MY_UNKNOWN_IMP1(IOutStream)\r
258 +\r
259 +  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize)\r
260 +  {\r
261 +         if (size > m_maxsize - m_offset) \r
262 +                 size = m_maxsize - m_offset;\r
263 +\r
264 +         if (size) {\r
265 +                 memcpy(m_data + m_offset, data, size);\r
266 +         }\r
267 +\r
268 +         m_offset += size;\r
269 +\r
270 +         if (m_offset > m_size)\r
271 +               m_size = m_offset;\r
272 +\r
273 +         if (processedSize) \r
274 +                 *processedSize = size;\r
275 +\r
276 +         return S_OK;\r
277 +  }\r
278 +  \r
279 +  STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize)\r
280 +  {\r
281 +         return Write(data, size, processedSize);\r
282 +  }\r
283 +\r
284 +  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)\r
285 +  {\r
286 +         UInt64 _offset;\r
287 +\r
288 +         if (seekOrigin == STREAM_SEEK_SET) _offset = offset;\r
289 +         else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset; \r
290 +         else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;\r
291 +         else return STG_E_INVALIDFUNCTION;\r
292 +\r
293 +         if (_offset < 0 || _offset > m_maxsize)\r
294 +                 return STG_E_SEEKERROR;\r
295 +\r
296 +         m_offset = _offset;\r
297 +\r
298 +         if (newPosition)\r
299 +                 *newPosition = m_offset;\r
300 +\r
301 +         return S_OK;\r
302 +  }\r
303 +  \r
304 +  STDMETHOD(SetSize)(Int64 newSize)\r
305 +  {\r
306 +         if ((UInt64)newSize > m_maxsize) \r
307 +                 return STG_E_MEDIUMFULL;\r
308 +\r
309 +         return S_OK;\r
310 +  }\r
311 +protected:\r
312 +       Bytef *m_data;\r
313 +       UInt64 m_size;\r
314 +       UInt64 m_maxsize;\r
315 +       UInt64 m_offset;\r
316 +};\r
317 +\r
318 +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest,   uLongf *destLen,\r
319 +                                  const Bytef *source, uLong sourceLen,\r
320 +                                  int level))\r
321 +{\r
322 +       CInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);\r
323 +       CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r
324 +       \r
325 +       COutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);\r
326 +       CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r
327 +       \r
328 +       NCompress::NLZMA::CEncoder *encoderSpec = \r
329 +               new NCompress::NLZMA::CEncoder;\r
330 +       CMyComPtr<ICompressCoder> encoder = encoderSpec;\r
331 +       \r
332 +       PROPID propIDs[] = \r
333 +       {\r
334 +               NCoderPropID::kDictionarySize,\r
335 +               NCoderPropID::kPosStateBits,\r
336 +               NCoderPropID::kLitContextBits,\r
337 +               NCoderPropID::kLitPosBits,\r
338 +               NCoderPropID::kAlgorithm,\r
339 +               NCoderPropID::kNumFastBytes,\r
340 +               NCoderPropID::kMatchFinder,\r
341 +               NCoderPropID::kEndMarker\r
342 +       };\r
343 +       const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);\r
344 +       \r
345 +       PROPVARIANT properties[kNumProps];\r
346 +       for (int p = 0; p < 6; p++)\r
347 +               properties[p].vt = VT_UI4;\r
348 +       properties[0].ulVal = UInt32(1 << (level + 14));\r
349 +       properties[1].ulVal = UInt32(ZLIB_PB);\r
350 +       properties[2].ulVal = UInt32(ZLIB_LC); // for normal files\r
351 +       properties[3].ulVal = UInt32(ZLIB_LP); // for normal files\r
352 +       properties[4].ulVal = UInt32(2);\r
353 +       properties[5].ulVal = UInt32(128);\r
354 +       \r
355 +       properties[6].vt = VT_BSTR;\r
356 +       properties[6].bstrVal = (BSTR)(const wchar_t *)L"BT4";\r
357 +       \r
358 +       properties[7].vt = VT_BOOL;\r
359 +       properties[7].boolVal = VARIANT_TRUE;\r
360 +       \r
361 +       if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)\r
362 +               return Z_MEM_ERROR; // should not happen\r
363 +       \r
364 +       HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);\r
365 +       if (result == E_OUTOFMEMORY)\r
366 +       {\r
367 +               return Z_MEM_ERROR;\r
368 +       }   \r
369 +       else if (result != S_OK)\r
370 +       {\r
371 +               return Z_BUF_ERROR;     // should not happen\r
372 +       }   \r
373 +       \r
374 +       UInt64 fileSize;\r
375 +       outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);\r
376 +       *destLen = fileSize;\r
377 +       \r
378 +       return Z_OK;\r
379 +}\r
380 +\r
381 +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest,   uLongf *destLen,\r
382 +                                   const Bytef *source, uLong sourceLen))\r
383 +{\r
384 +       CInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);\r
385 +       CMyComPtr<ISequentialInStream> inStream = inStreamSpec;\r
386 +       \r
387 +       COutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);\r
388 +       CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;\r
389 +       \r
390 +       NCompress::NLZMA::CDecoder *decoderSpec = \r
391 +               new NCompress::NLZMA::CDecoder;\r
392 +       CMyComPtr<ICompressCoder> decoder = decoderSpec;\r
393 +       \r
394 +       if (decoderSpec->SetDecoderPropertiesRaw(ZLIB_LC, \r
395 +               ZLIB_LP, ZLIB_PB, (1 << 23)) != S_OK) return Z_DATA_ERROR;\r
396 +       \r
397 +       UInt64 fileSize = *destLen;\r
398 +       \r
399 +       if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)\r
400 +       {\r
401 +               return Z_DATA_ERROR;\r
402 +       }\r
403 +       \r
404 +       outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);\r
405 +       *destLen = fileSize;\r
406 +       \r
407 +       return Z_OK;\r
408 +}\r