strip the kernel version suffix from target directories, except for brcm-2.4 (the...
[openwrt/staging/florian.git] / target / linux / etrax / patches / generic_2.6 / 002-lzma_decompress.patch
1 --- linux-2.6.19.old/lib/Makefile 2007-04-18 17:41:22.679403384 +0200
2 +++ linux-2.6.19.dev/lib/Makefile 2007-04-18 17:41:43.303268080 +0200
3 @@ -54,6 +54,7 @@
4 obj-$(CONFIG_AUDIT_GENERIC) += audit.o
5
6 obj-$(CONFIG_SWIOTLB) += swiotlb.o
7 +obj-y += LzmaDecode.o
8
9 hostprogs-y := gen_crc32table
10 clean-files := crc32table.h
11 --- linux-2.6.19.old/lib/LzmaDecode.c 1970-01-01 01:00:00.000000000 +0100
12 +++ linux-2.6.19.dev/lib/LzmaDecode.c 2006-12-14 03:13:20.000000000 +0100
13 @@ -0,0 +1,663 @@
14 +/*
15 + LzmaDecode.c
16 + LZMA Decoder
17 +
18 + LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)
19 + http://www.7-zip.org/
20 +
21 + LZMA SDK is licensed under two licenses:
22 + 1) GNU Lesser General Public License (GNU LGPL)
23 + 2) Common Public License (CPL)
24 + It means that you can select one of these two licenses and
25 + follow rules of that license.
26 +
27 + SPECIAL EXCEPTION:
28 + Igor Pavlov, as the author of this code, expressly permits you to
29 + statically or dynamically link your code (or bind by name) to the
30 + interfaces of this file without subjecting your linked code to the
31 + terms of the CPL or GNU LGPL. Any modifications or additions
32 + to this file, however, are subject to the LGPL or CPL terms.
33 +*/
34 +
35 +#include <linux/LzmaDecode.h>
36 +
37 +#ifndef Byte
38 +#define Byte unsigned char
39 +#endif
40 +
41 +#define kNumTopBits 24
42 +#define kTopValue ((UInt32)1 << kNumTopBits)
43 +
44 +#define kNumBitModelTotalBits 11
45 +#define kBitModelTotal (1 << kNumBitModelTotalBits)
46 +#define kNumMoveBits 5
47 +
48 +typedef struct _CRangeDecoder
49 +{
50 + Byte *Buffer;
51 + Byte *BufferLim;
52 + UInt32 Range;
53 + UInt32 Code;
54 + #ifdef _LZMA_IN_CB
55 + ILzmaInCallback *InCallback;
56 + int Result;
57 + #endif
58 + int ExtraBytes;
59 +} CRangeDecoder;
60 +
61 +Byte RangeDecoderReadByte(CRangeDecoder *rd)
62 +{
63 + if (rd->Buffer == rd->BufferLim)
64 + {
65 + #ifdef _LZMA_IN_CB
66 + UInt32 size;
67 + rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);
68 + rd->BufferLim = rd->Buffer + size;
69 + if (size == 0)
70 + #endif
71 + {
72 + rd->ExtraBytes = 1;
73 + return 0xFF;
74 + }
75 + }
76 + return (*rd->Buffer++);
77 +}
78 +
79 +/* #define ReadByte (*rd->Buffer++) */
80 +#define ReadByte (RangeDecoderReadByte(rd))
81 +
82 +void RangeDecoderInit(CRangeDecoder *rd,
83 + #ifdef _LZMA_IN_CB
84 + ILzmaInCallback *inCallback
85 + #else
86 + Byte *stream, UInt32 bufferSize
87 + #endif
88 + )
89 +{
90 + int i;
91 + #ifdef _LZMA_IN_CB
92 + rd->InCallback = inCallback;
93 + rd->Buffer = rd->BufferLim = 0;
94 + #else
95 + rd->Buffer = stream;
96 + rd->BufferLim = stream + bufferSize;
97 + #endif
98 + rd->ExtraBytes = 0;
99 + rd->Code = 0;
100 + rd->Range = (0xFFFFFFFF);
101 + for(i = 0; i < 5; i++)
102 + rd->Code = (rd->Code << 8) | ReadByte;
103 +}
104 +
105 +#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;
106 +#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;
107 +#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }
108 +
109 +UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)
110 +{
111 + RC_INIT_VAR
112 + UInt32 result = 0;
113 + int i;
114 + for (i = numTotalBits; i > 0; i--)
115 + {
116 + /* UInt32 t; */
117 + range >>= 1;
118 +
119 + result <<= 1;
120 + if (code >= range)
121 + {
122 + code -= range;
123 + result |= 1;
124 + }
125 + /*
126 + t = (code - range) >> 31;
127 + t &= 1;
128 + code -= range & (t - 1);
129 + result = (result + result) | (1 - t);
130 + */
131 + RC_NORMALIZE
132 + }
133 + RC_FLUSH_VAR
134 + return result;
135 +}
136 +
137 +int RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)
138 +{
139 + UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;
140 + if (rd->Code < bound)
141 + {
142 + rd->Range = bound;
143 + *prob += (kBitModelTotal - *prob) >> kNumMoveBits;
144 + if (rd->Range < kTopValue)
145 + {
146 + rd->Code = (rd->Code << 8) | ReadByte;
147 + rd->Range <<= 8;
148 + }
149 + return 0;
150 + }
151 + else
152 + {
153 + rd->Range -= bound;
154 + rd->Code -= bound;
155 + *prob -= (*prob) >> kNumMoveBits;
156 + if (rd->Range < kTopValue)
157 + {
158 + rd->Code = (rd->Code << 8) | ReadByte;
159 + rd->Range <<= 8;
160 + }
161 + return 1;
162 + }
163 +}
164 +
165 +#define RC_GET_BIT2(prob, mi, A0, A1) \
166 + UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \
167 + if (code < bound) \
168 + { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \
169 + else \
170 + { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \
171 + RC_NORMALIZE
172 +
173 +#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)
174 +
175 +int RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
176 +{
177 + int mi = 1;
178 + int i;
179 + #ifdef _LZMA_LOC_OPT
180 + RC_INIT_VAR
181 + #endif
182 + for(i = numLevels; i > 0; i--)
183 + {
184 + #ifdef _LZMA_LOC_OPT
185 + CProb *prob = probs + mi;
186 + RC_GET_BIT(prob, mi)
187 + #else
188 + mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);
189 + #endif
190 + }
191 + #ifdef _LZMA_LOC_OPT
192 + RC_FLUSH_VAR
193 + #endif
194 + return mi - (1 << numLevels);
195 +}
196 +
197 +int RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
198 +{
199 + int mi = 1;
200 + int i;
201 + int symbol = 0;
202 + #ifdef _LZMA_LOC_OPT
203 + RC_INIT_VAR
204 + #endif
205 + for(i = 0; i < numLevels; i++)
206 + {
207 + #ifdef _LZMA_LOC_OPT
208 + CProb *prob = probs + mi;
209 + RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))
210 + #else
211 + int bit = RangeDecoderBitDecode(probs + mi, rd);
212 + mi = mi + mi + bit;
213 + symbol |= (bit << i);
214 + #endif
215 + }
216 + #ifdef _LZMA_LOC_OPT
217 + RC_FLUSH_VAR
218 + #endif
219 + return symbol;
220 +}
221 +
222 +Byte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)
223 +{
224 + int symbol = 1;
225 + #ifdef _LZMA_LOC_OPT
226 + RC_INIT_VAR
227 + #endif
228 + do
229 + {
230 + #ifdef _LZMA_LOC_OPT
231 + CProb *prob = probs + symbol;
232 + RC_GET_BIT(prob, symbol)
233 + #else
234 + symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
235 + #endif
236 + }
237 + while (symbol < 0x100);
238 + #ifdef _LZMA_LOC_OPT
239 + RC_FLUSH_VAR
240 + #endif
241 + return symbol;
242 +}
243 +
244 +Byte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)
245 +{
246 + int symbol = 1;
247 + #ifdef _LZMA_LOC_OPT
248 + RC_INIT_VAR
249 + #endif
250 + do
251 + {
252 + int bit;
253 + int matchBit = (matchByte >> 7) & 1;
254 + matchByte <<= 1;
255 + #ifdef _LZMA_LOC_OPT
256 + {
257 + CProb *prob = probs + ((1 + matchBit) << 8) + symbol;
258 + RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)
259 + }
260 + #else
261 + bit = RangeDecoderBitDecode(probs + ((1 + matchBit) << 8) + symbol, rd);
262 + symbol = (symbol << 1) | bit;
263 + #endif
264 + if (matchBit != bit)
265 + {
266 + while (symbol < 0x100)
267 + {
268 + #ifdef _LZMA_LOC_OPT
269 + CProb *prob = probs + symbol;
270 + RC_GET_BIT(prob, symbol)
271 + #else
272 + symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
273 + #endif
274 + }
275 + break;
276 + }
277 + }
278 + while (symbol < 0x100);
279 + #ifdef _LZMA_LOC_OPT
280 + RC_FLUSH_VAR
281 + #endif
282 + return symbol;
283 +}
284 +
285 +#define kNumPosBitsMax 4
286 +#define kNumPosStatesMax (1 << kNumPosBitsMax)
287 +
288 +#define kLenNumLowBits 3
289 +#define kLenNumLowSymbols (1 << kLenNumLowBits)
290 +#define kLenNumMidBits 3
291 +#define kLenNumMidSymbols (1 << kLenNumMidBits)
292 +#define kLenNumHighBits 8
293 +#define kLenNumHighSymbols (1 << kLenNumHighBits)
294 +
295 +#define LenChoice 0
296 +#define LenChoice2 (LenChoice + 1)
297 +#define LenLow (LenChoice2 + 1)
298 +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
299 +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
300 +#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
301 +
302 +int LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)
303 +{
304 + if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)
305 + return RangeDecoderBitTreeDecode(p + LenLow +
306 + (posState << kLenNumLowBits), kLenNumLowBits, rd);
307 + if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)
308 + return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +
309 + (posState << kLenNumMidBits), kLenNumMidBits, rd);
310 + return kLenNumLowSymbols + kLenNumMidSymbols +
311 + RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);
312 +}
313 +
314 +#define kNumStates 12
315 +
316 +#define kStartPosModelIndex 4
317 +#define kEndPosModelIndex 14
318 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
319 +
320 +#define kNumPosSlotBits 6
321 +#define kNumLenToPosStates 4
322 +
323 +#define kNumAlignBits 4
324 +#define kAlignTableSize (1 << kNumAlignBits)
325 +
326 +#define kMatchMinLen 2
327 +
328 +#define IsMatch 0
329 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
330 +#define IsRepG0 (IsRep + kNumStates)
331 +#define IsRepG1 (IsRepG0 + kNumStates)
332 +#define IsRepG2 (IsRepG1 + kNumStates)
333 +#define IsRep0Long (IsRepG2 + kNumStates)
334 +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
335 +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
336 +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
337 +#define LenCoder (Align + kAlignTableSize)
338 +#define RepLenCoder (LenCoder + kNumLenProbs)
339 +#define Literal (RepLenCoder + kNumLenProbs)
340 +
341 +#if Literal != LZMA_BASE_SIZE
342 +StopCompilingDueBUG
343 +#endif
344 +
345 +#ifdef _LZMA_OUT_READ
346 +
347 +typedef struct _LzmaVarState
348 +{
349 + CRangeDecoder RangeDecoder;
350 + Byte *Dictionary;
351 + UInt32 DictionarySize;
352 + UInt32 DictionaryPos;
353 + UInt32 GlobalPos;
354 + UInt32 Reps[4];
355 + int lc;
356 + int lp;
357 + int pb;
358 + int State;
359 + int PreviousIsMatch;
360 + int RemainLen;
361 +} LzmaVarState;
362 +
363 +int LzmaDecoderInit(
364 + unsigned char *buffer, UInt32 bufferSize,
365 + int lc, int lp, int pb,
366 + unsigned char *dictionary, UInt32 dictionarySize,
367 + #ifdef _LZMA_IN_CB
368 + ILzmaInCallback *inCallback
369 + #else
370 + unsigned char *inStream, UInt32 inSize
371 + #endif
372 + )
373 +{
374 + LzmaVarState *vs = (LzmaVarState *)buffer;
375 + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
376 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
377 + UInt32 i;
378 + if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState))
379 + return LZMA_RESULT_NOT_ENOUGH_MEM;
380 + vs->Dictionary = dictionary;
381 + vs->DictionarySize = dictionarySize;
382 + vs->DictionaryPos = 0;
383 + vs->GlobalPos = 0;
384 + vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1;
385 + vs->lc = lc;
386 + vs->lp = lp;
387 + vs->pb = pb;
388 + vs->State = 0;
389 + vs->PreviousIsMatch = 0;
390 + vs->RemainLen = 0;
391 + dictionary[dictionarySize - 1] = 0;
392 + for (i = 0; i < numProbs; i++)
393 + p[i] = kBitModelTotal >> 1;
394 + RangeDecoderInit(&vs->RangeDecoder,
395 + #ifdef _LZMA_IN_CB
396 + inCallback
397 + #else
398 + inStream, inSize
399 + #endif
400 + );
401 + return LZMA_RESULT_OK;
402 +}
403 +
404 +int LzmaDecode(unsigned char *buffer,
405 + unsigned char *outStream, UInt32 outSize,
406 + UInt32 *outSizeProcessed)
407 +{
408 + LzmaVarState *vs = (LzmaVarState *)buffer;
409 + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
410 + CRangeDecoder rd = vs->RangeDecoder;
411 + int state = vs->State;
412 + int previousIsMatch = vs->PreviousIsMatch;
413 + Byte previousByte;
414 + UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
415 + UInt32 nowPos = 0;
416 + UInt32 posStateMask = (1 << (vs->pb)) - 1;
417 + UInt32 literalPosMask = (1 << (vs->lp)) - 1;
418 + int lc = vs->lc;
419 + int len = vs->RemainLen;
420 + UInt32 globalPos = vs->GlobalPos;
421 +
422 + Byte *dictionary = vs->Dictionary;
423 + UInt32 dictionarySize = vs->DictionarySize;
424 + UInt32 dictionaryPos = vs->DictionaryPos;
425 +
426 + if (len == -1)
427 + {
428 + *outSizeProcessed = 0;
429 + return LZMA_RESULT_OK;
430 + }
431 +
432 + while(len > 0 && nowPos < outSize)
433 + {
434 + UInt32 pos = dictionaryPos - rep0;
435 + if (pos >= dictionarySize)
436 + pos += dictionarySize;
437 + outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
438 + if (++dictionaryPos == dictionarySize)
439 + dictionaryPos = 0;
440 + len--;
441 + }
442 + if (dictionaryPos == 0)
443 + previousByte = dictionary[dictionarySize - 1];
444 + else
445 + previousByte = dictionary[dictionaryPos - 1];
446 +#else
447 +
448 +int LzmaDecode(
449 + Byte *buffer, UInt32 bufferSize,
450 + int lc, int lp, int pb,
451 + #ifdef _LZMA_IN_CB
452 + ILzmaInCallback *inCallback,
453 + #else
454 + unsigned char *inStream, UInt32 inSize,
455 + #endif
456 + unsigned char *outStream, UInt32 outSize,
457 + UInt32 *outSizeProcessed)
458 +{
459 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
460 + CProb *p = (CProb *)buffer;
461 + CRangeDecoder rd;
462 + UInt32 i;
463 + int state = 0;
464 + int previousIsMatch = 0;
465 + Byte previousByte = 0;
466 + UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
467 + UInt32 nowPos = 0;
468 + UInt32 posStateMask = (1 << pb) - 1;
469 + UInt32 literalPosMask = (1 << lp) - 1;
470 + int len = 0;
471 + if (bufferSize < numProbs * sizeof(CProb))
472 + return LZMA_RESULT_NOT_ENOUGH_MEM;
473 + for (i = 0; i < numProbs; i++)
474 + p[i] = kBitModelTotal >> 1;
475 + RangeDecoderInit(&rd,
476 + #ifdef _LZMA_IN_CB
477 + inCallback
478 + #else
479 + inStream, inSize
480 + #endif
481 + );
482 +#endif
483 +
484 + *outSizeProcessed = 0;
485 + while(nowPos < outSize)
486 + {
487 + int posState = (int)(
488 + (nowPos
489 + #ifdef _LZMA_OUT_READ
490 + + globalPos
491 + #endif
492 + )
493 + & posStateMask);
494 + #ifdef _LZMA_IN_CB
495 + if (rd.Result != LZMA_RESULT_OK)
496 + return rd.Result;
497 + #endif
498 + if (rd.ExtraBytes != 0)
499 + return LZMA_RESULT_DATA_ERROR;
500 + if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)
501 + {
502 + CProb *probs = p + Literal + (LZMA_LIT_SIZE *
503 + (((
504 + (nowPos
505 + #ifdef _LZMA_OUT_READ
506 + + globalPos
507 + #endif
508 + )
509 + & literalPosMask) << lc) + (previousByte >> (8 - lc))));
510 +
511 + if (state < 4) state = 0;
512 + else if (state < 10) state -= 3;
513 + else state -= 6;
514 + if (previousIsMatch)
515 + {
516 + Byte matchByte;
517 + #ifdef _LZMA_OUT_READ
518 + UInt32 pos = dictionaryPos - rep0;
519 + if (pos >= dictionarySize)
520 + pos += dictionarySize;
521 + matchByte = dictionary[pos];
522 + #else
523 + matchByte = outStream[nowPos - rep0];
524 + #endif
525 + previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);
526 + previousIsMatch = 0;
527 + }
528 + else
529 + previousByte = LzmaLiteralDecode(probs, &rd);
530 + outStream[nowPos++] = previousByte;
531 + #ifdef _LZMA_OUT_READ
532 + dictionary[dictionaryPos] = previousByte;
533 + if (++dictionaryPos == dictionarySize)
534 + dictionaryPos = 0;
535 + #endif
536 + }
537 + else
538 + {
539 + previousIsMatch = 1;
540 + if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)
541 + {
542 + if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)
543 + {
544 + if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)
545 + {
546 + #ifdef _LZMA_OUT_READ
547 + UInt32 pos;
548 + #endif
549 + if (
550 + (nowPos
551 + #ifdef _LZMA_OUT_READ
552 + + globalPos
553 + #endif
554 + )
555 + == 0)
556 + return LZMA_RESULT_DATA_ERROR;
557 + state = state < 7 ? 9 : 11;
558 + #ifdef _LZMA_OUT_READ
559 + pos = dictionaryPos - rep0;
560 + if (pos >= dictionarySize)
561 + pos += dictionarySize;
562 + previousByte = dictionary[pos];
563 + dictionary[dictionaryPos] = previousByte;
564 + if (++dictionaryPos == dictionarySize)
565 + dictionaryPos = 0;
566 + #else
567 + previousByte = outStream[nowPos - rep0];
568 + #endif
569 + outStream[nowPos++] = previousByte;
570 + continue;
571 + }
572 + }
573 + else
574 + {
575 + UInt32 distance;
576 + if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)
577 + distance = rep1;
578 + else
579 + {
580 + if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)
581 + distance = rep2;
582 + else
583 + {
584 + distance = rep3;
585 + rep3 = rep2;
586 + }
587 + rep2 = rep1;
588 + }
589 + rep1 = rep0;
590 + rep0 = distance;
591 + }
592 + len = LzmaLenDecode(p + RepLenCoder, &rd, posState);
593 + state = state < 7 ? 8 : 11;
594 + }
595 + else
596 + {
597 + int posSlot;
598 + rep3 = rep2;
599 + rep2 = rep1;
600 + rep1 = rep0;
601 + state = state < 7 ? 7 : 10;
602 + len = LzmaLenDecode(p + LenCoder, &rd, posState);
603 + posSlot = RangeDecoderBitTreeDecode(p + PosSlot +
604 + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
605 + kNumPosSlotBits), kNumPosSlotBits, &rd);
606 + if (posSlot >= kStartPosModelIndex)
607 + {
608 + int numDirectBits = ((posSlot >> 1) - 1);
609 + rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);
610 + if (posSlot < kEndPosModelIndex)
611 + {
612 + rep0 += RangeDecoderReverseBitTreeDecode(
613 + p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);
614 + }
615 + else
616 + {
617 + rep0 += RangeDecoderDecodeDirectBits(&rd,
618 + numDirectBits - kNumAlignBits) << kNumAlignBits;
619 + rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);
620 + }
621 + }
622 + else
623 + rep0 = posSlot;
624 + rep0++;
625 + }
626 + if (rep0 == (UInt32)(0))
627 + {
628 + /* it's for stream version */
629 + len = -1;
630 + break;
631 + }
632 + if (rep0 > nowPos
633 + #ifdef _LZMA_OUT_READ
634 + + globalPos
635 + #endif
636 + )
637 + {
638 + return LZMA_RESULT_DATA_ERROR;
639 + }
640 + len += kMatchMinLen;
641 + do
642 + {
643 + #ifdef _LZMA_OUT_READ
644 + UInt32 pos = dictionaryPos - rep0;
645 + if (pos >= dictionarySize)
646 + pos += dictionarySize;
647 + previousByte = dictionary[pos];
648 + dictionary[dictionaryPos] = previousByte;
649 + if (++dictionaryPos == dictionarySize)
650 + dictionaryPos = 0;
651 + #else
652 + previousByte = outStream[nowPos - rep0];
653 + #endif
654 + outStream[nowPos++] = previousByte;
655 + len--;
656 + }
657 + while(len > 0 && nowPos < outSize);
658 + }
659 + }
660 +
661 + #ifdef _LZMA_OUT_READ
662 + vs->RangeDecoder = rd;
663 + vs->DictionaryPos = dictionaryPos;
664 + vs->GlobalPos = globalPos + nowPos;
665 + vs->Reps[0] = rep0;
666 + vs->Reps[1] = rep1;
667 + vs->Reps[2] = rep2;
668 + vs->Reps[3] = rep3;
669 + vs->State = state;
670 + vs->PreviousIsMatch = previousIsMatch;
671 + vs->RemainLen = len;
672 + #endif
673 +
674 + *outSizeProcessed = nowPos;
675 + return LZMA_RESULT_OK;
676 +}
677 --- linux-2.6.19.old/include/linux/LzmaDecode.h 1970-01-01 01:00:00.000000000 +0100
678 +++ linux-2.6.19.dev/include/linux/LzmaDecode.h 2006-12-14 03:13:20.000000000 +0100
679 @@ -0,0 +1,100 @@
680 +/*
681 + LzmaDecode.h
682 + LZMA Decoder interface
683 +
684 + LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)
685 + http://www.7-zip.org/
686 +
687 + LZMA SDK is licensed under two licenses:
688 + 1) GNU Lesser General Public License (GNU LGPL)
689 + 2) Common Public License (CPL)
690 + It means that you can select one of these two licenses and
691 + follow rules of that license.
692 +
693 + SPECIAL EXCEPTION:
694 + Igor Pavlov, as the author of this code, expressly permits you to
695 + statically or dynamically link your code (or bind by name) to the
696 + interfaces of this file without subjecting your linked code to the
697 + terms of the CPL or GNU LGPL. Any modifications or additions
698 + to this file, however, are subject to the LGPL or CPL terms.
699 +*/
700 +
701 +#ifndef __LZMADECODE_H
702 +#define __LZMADECODE_H
703 +
704 +/* #define _LZMA_IN_CB */
705 +/* Use callback for input data */
706 +
707 +/* #define _LZMA_OUT_READ */
708 +/* Use read function for output data */
709 +
710 +/* #define _LZMA_PROB32 */
711 +/* It can increase speed on some 32-bit CPUs,
712 + but memory usage will be doubled in that case */
713 +
714 +/* #define _LZMA_LOC_OPT */
715 +/* Enable local speed optimizations inside code */
716 +
717 +#ifndef UInt32
718 +#ifdef _LZMA_UINT32_IS_ULONG
719 +#define UInt32 unsigned long
720 +#else
721 +#define UInt32 unsigned int
722 +#endif
723 +#endif
724 +
725 +#ifdef _LZMA_PROB32
726 +#define CProb UInt32
727 +#else
728 +#define CProb unsigned short
729 +#endif
730 +
731 +#define LZMA_RESULT_OK 0
732 +#define LZMA_RESULT_DATA_ERROR 1
733 +#define LZMA_RESULT_NOT_ENOUGH_MEM 2
734 +
735 +#ifdef _LZMA_IN_CB
736 +typedef struct _ILzmaInCallback
737 +{
738 + int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize);
739 +} ILzmaInCallback;
740 +#endif
741 +
742 +#define LZMA_BASE_SIZE 1846
743 +#define LZMA_LIT_SIZE 768
744 +
745 +/*
746 +bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb)
747 +bufferSize += 100 in case of _LZMA_OUT_READ
748 +by default CProb is unsigned short,
749 +but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int)
750 +*/
751 +
752 +#ifdef _LZMA_OUT_READ
753 +int LzmaDecoderInit(
754 + unsigned char *buffer, UInt32 bufferSize,
755 + int lc, int lp, int pb,
756 + unsigned char *dictionary, UInt32 dictionarySize,
757 + #ifdef _LZMA_IN_CB
758 + ILzmaInCallback *inCallback
759 + #else
760 + unsigned char *inStream, UInt32 inSize
761 + #endif
762 +);
763 +#endif
764 +
765 +int LzmaDecode(
766 + unsigned char *buffer,
767 + #ifndef _LZMA_OUT_READ
768 + UInt32 bufferSize,
769 + int lc, int lp, int pb,
770 + #ifdef _LZMA_IN_CB
771 + ILzmaInCallback *inCallback,
772 + #else
773 + unsigned char *inStream, UInt32 inSize,
774 + #endif
775 + #endif
776 + unsigned char *outStream, UInt32 outSize,
777 + UInt32 *outSizeProcessed);
778 +
779 +#endif
780