]> git.pld-linux.org Git - packages/busybox.git/blob - busybox-lzmacat.diff
- dropped, use mdadm instead
[packages/busybox.git] / busybox-lzmacat.diff
1 --- busybox-20050614.orig/archival/libunarchive/lzmacat.c       1970-01-01 01:00:00.000000000 +0100
2 +++ busybox-20050614/archival/lzmacat.c 2005-06-15 02:13:51.000000000 +0200
3 @@ -0,0 +1,190 @@
4 +/* 
5 +    lzmacat.c
6 +
7 +    Copyright (C) 1999-2004 Igor Pavlov (2005-03-18))
8 +        examplecode from the LZMA DSK
9 +    Copyright (C) 2005 Christian Leber
10 +        changed to lzmcacat functionality
11 +
12 +    This program is free software; you can redistribute it and/or modify
13 +    it under the terms of the GNU General Public License as published by
14 +    the Free Software Foundation; either version 2 of the License, or
15 +    (at your option) any later version.
16 +
17 +    This program is distributed in the hope that it will be useful,
18 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
19 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 +    GNU General Public License for more details.
21 +
22 +    You should have received a copy of the GNU General Public License
23 +    along with this program; if not, write to the Free Software
24 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 +
26 +    e-mail: christian@leber.de
27 +*/
28 +
29 +#include <stdio.h>
30 +#include <stdlib.h>
31 +#include <string.h>
32 +#include <unistd.h>
33 +
34 +#include "busybox.h"
35 +#include "libunarchive/LzmaDecode.h"
36 +
37 +#define _LZMA_READ_BUFFER_SIZE 0x10000
38 +#define _LZMA_WRITE_BUFFER_SIZE 0x10000
39 +
40 +#ifdef _LZMA_IN_CB
41 +typedef struct _CBuffer
42 +{
43 +       ILzmaInCallback InCallback;
44 +       unsigned char *Buffer;
45 +       FILE *fil;
46 +} CBuffer;
47 +
48 +int LzmaReadCompressed(void *object, unsigned char **buffer, unsigned int *size)
49 +{
50 +       CBuffer *bo = (CBuffer *)object;
51 +       /* try to read _LZMA_READ_SIZE bytes */
52 +       *size = fread(bo->Buffer,1,
53 +               _LZMA_READ_BUFFER_SIZE,bo->fil);
54 +       *buffer = bo->Buffer;
55 +       return LZMA_RESULT_OK;
56 +}
57 +#endif
58 +
59 +int lzmacat_main(int argc, char **argv)
60 +{
61 +       FILE *inputHandle;
62 +       unsigned int outSize, outSizeProcessed, lzmaInternalSize;
63 +       void *lzmaInternalData;
64 +       unsigned char header[13];
65 +       unsigned char prop0;
66 +       unsigned char *out_buffer;
67 +       int i, res;
68 +       int lc, lp, pb;
69 +       CBuffer bo;
70 +       UInt32 nowPos;
71 +       unsigned char *dictionary;
72 +       UInt32 dictionarySize = 0;
73 +
74 +       if (argc != 2) {
75 +               fprintf(stderr, "lzmacat\n");
76 +               fprintf(stderr, "Usage:  lzmaDec file.lzma\n");
77 +               return 1;
78 +       }
79 +       
80 +       inputHandle = fopen(argv[1], "rb");
81 +       if (inputHandle == 0) {
82 +               fprintf(stderr, "Open input file errori\n");
83 +               return 1;
84 +       }
85 +
86 +       if (!fread(header, 1, sizeof(header),inputHandle)) {
87 +               fprintf(stderr, "Can't read header\n");
88 +               return 1;
89 +       }
90 +       
91 +       outSize = 0;
92 +       for (i = 0; i < 4; i++) {
93 +               outSize += (unsigned int)(header[5+i]) << (i * 8);
94 +       }
95 +       
96 +       if (outSize == 0xFFFFFFFF) {
97 +               fprintf(stderr, "stream version is not supported\n");
98 +               return 1;
99 +       }
100 +       
101 +       for (i = 0; i < 4; i++) {
102 +               if (header[9+i] != 0) {
103 +                       fprintf(stderr, "file too big (bigger than 4 GB)\n");
104 +                       return 1;
105 +               }
106 +       }
107 +
108 +       prop0 = header[0];
109 +       if (prop0 >= (9*5*5)) {
110 +               fprintf(stderr, "Properties error\n");
111 +               return 1;
112 +       }
113 +       pb = prop0 / 45;
114 +       prop0 = prop0 % 45;
115 +       lp = prop0 / 9;
116 +       lc = prop0 % 9;
117 +       lzmaInternalSize = 
118 +               (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb);
119 +       /* because we a reusing _LZMA_OUT_READ */
120 +       lzmaInternalSize += 100;
121 +
122 +       lzmaInternalData = malloc(lzmaInternalSize);
123 +       if (lzmaInternalData == 0) {
124 +               fprintf(stderr, "malloc error!\n");
125 +               return 1;
126 +       }
127 +       
128 +       bo.InCallback.Read = LzmaReadCompressed;
129 +       bo.Buffer = malloc(_LZMA_READ_BUFFER_SIZE);
130 +       if (bo.Buffer == 0) {
131 +               fprintf(stderr, "malloc error!\n");
132 +               free(lzmaInternalData);
133 +               return 1;
134 +       }
135 +       bo.fil = inputHandle;
136 +
137 +       for (i = 0; i < 4; i++) {
138 +               dictionarySize += (UInt32)(header[1 + i]) << (i * 8);
139 +       }
140 +       
141 +       if (dictionarySize == 0) {
142 +               dictionarySize = 1;
143 +               /* LZMA decoder can not work with dictionarySize = 0 */
144 +       }
145 +
146 +       dictionary = (unsigned char *)malloc(dictionarySize);
147 +       if (dictionary == 0) {
148 +               fprintf(stderr, "malloc error!\n");
149 +               free(lzmaInternalData);
150 +               free(bo.Buffer);
151 +               return 1;
152 +       }
153 +       res = LzmaDecoderInit((unsigned char *)lzmaInternalData,
154 +                       lzmaInternalSize,
155 +                       lc, lp, pb,
156 +                       dictionary, dictionarySize,
157 +                       &bo.InCallback);
158 +       if (res == 0) {
159 +               out_buffer = malloc (_LZMA_WRITE_BUFFER_SIZE);
160 +               if(out_buffer==0) {
161 +                       fprintf(stderr, "malloc error!\n");
162 +                       free(lzmaInternalData);
163 +                       free(bo.Buffer);
164 +                       free(dictionary);
165 +                       return 1;
166 +               }
167 +               for (nowPos = 0; nowPos < outSize;) {
168 +                       UInt32 blockSize = outSize - nowPos;
169 +                       if (blockSize > _LZMA_WRITE_BUFFER_SIZE)
170 +                               blockSize = _LZMA_WRITE_BUFFER_SIZE;
171 +                       res = LzmaDecode((unsigned char *)lzmaInternalData, 
172 +                               out_buffer, blockSize, &outSizeProcessed);
173 +                       if (res != 0)
174 +                               break;
175 +                       if (outSizeProcessed == 0) {
176 +                               outSize = nowPos;
177 +                               break;
178 +                       }
179 +                       nowPos += outSizeProcessed;
180 +                       write(fileno(stdout),out_buffer,outSizeProcessed);
181 +               }
182 +       }
183 +       free(lzmaInternalData);
184 +       free(bo.Buffer);
185 +       free(dictionary);
186 +       free(out_buffer);
187 +       if (res != 0) {
188 +               fprintf(stderr, "\nerror = %d\n", res);
189 +               return 1;
190 +       }
191 +       return 0;
192 +}
193 +
194 --- busybox-20050614.orig/archival/libunarchive/LzmaDecode.c    1970-01-01 01:00:00.000000000 +0100
195 +++ busybox-20050614/archival/libunarchive/LzmaDecode.c 2005-06-15 02:13:59.000000000 +0200
196 @@ -0,0 +1,586 @@
197 +/*
198 +  LzmaDecode.c
199 +  LZMA Decoder (optimized for Speed version)
200 +  
201 +  LZMA SDK 4.17 Copyright (c) 1999-2005 Igor Pavlov (2005-04-05)
202 +  http://www.7-zip.org/
203 +
204 +  LZMA SDK is licensed under two licenses:
205 +  1) GNU Lesser General Public License (GNU LGPL)
206 +  2) Common Public License (CPL)
207 +  It means that you can select one of these two licenses and 
208 +  follow rules of that license.
209 +
210 +  SPECIAL EXCEPTION:
211 +  Igor Pavlov, as the author of this Code, expressly permits you to 
212 +  statically or dynamically link your Code (or bind by name) to the 
213 +  interfaces of this file without subjecting your linked Code to the 
214 +  terms of the CPL or GNU LGPL. Any modifications or additions 
215 +  to this file, however, are subject to the LGPL or CPL terms.
216 +*/
217 +
218 +#include "LzmaDecode.h"
219 +
220 +#ifndef Byte
221 +#define Byte unsigned char
222 +#endif
223 +
224 +#define kNumTopBits 24
225 +#define kTopValue ((UInt32)1 << kNumTopBits)
226 +
227 +#define kNumBitModelTotalBits 11
228 +#define kBitModelTotal (1 << kNumBitModelTotalBits)
229 +#define kNumMoveBits 5
230 +
231 +#define RC_READ_BYTE (*Buffer++)
232 +
233 +#define RC_INIT2 Code = 0; Range = 0xFFFFFFFF; \
234 +  { int i; for(i = 0; i < 5; i++) { RC_TEST; Code = (Code << 8) | RC_READ_BYTE; }}
235 +
236 +#ifdef _LZMA_IN_CB
237 +
238 +#define RC_TEST { if (Buffer == BufferLim) \
239 +  { UInt32 size; int result = InCallback->Read(InCallback, &Buffer, &size); if (result != LZMA_RESULT_OK) return result; \
240 +  BufferLim = Buffer + size; if (size == 0) return LZMA_RESULT_DATA_ERROR; }}
241 +
242 +#define RC_INIT Buffer = BufferLim = 0; RC_INIT2
243 +
244 +#else
245 +
246 +#define RC_TEST { if (Buffer == BufferLim) return LZMA_RESULT_DATA_ERROR; }
247 +
248 +#define RC_INIT(buffer, bufferSize) Buffer = buffer; BufferLim = buffer + bufferSize; RC_INIT2
249
250 +#endif
251 +
252 +#define RC_NORMALIZE if (Range < kTopValue) { RC_TEST; Range <<= 8; Code = (Code << 8) | RC_READ_BYTE; }
253 +
254 +#define IfBit0(p) RC_NORMALIZE; bound = (Range >> kNumBitModelTotalBits) * *(p); if (Code < bound)
255 +#define UpdateBit0(p) Range = bound; *(p) += (kBitModelTotal - *(p)) >> kNumMoveBits;
256 +#define UpdateBit1(p) Range -= bound; Code -= bound; *(p) -= (*(p)) >> kNumMoveBits;
257 +
258 +#define RC_GET_BIT2(p, mi, A0, A1) IfBit0(p) \
259 +  { UpdateBit0(p); mi <<= 1; A0; } else \
260 +  { UpdateBit1(p); mi = (mi + mi) + 1; A1; } 
261 +  
262 +#define RC_GET_BIT(p, mi) RC_GET_BIT2(p, mi, ; , ;)               
263 +
264 +#define RangeDecoderBitTreeDecode(probs, numLevels, res) \
265 +  { int i = numLevels; res = 1; \
266 +  do { CProb *p = probs + res; RC_GET_BIT(p, res) } while(--i != 0); \
267 +  res -= (1 << numLevels); }
268 +
269 +
270 +#define kNumPosBitsMax 4
271 +#define kNumPosStatesMax (1 << kNumPosBitsMax)
272 +
273 +#define kLenNumLowBits 3
274 +#define kLenNumLowSymbols (1 << kLenNumLowBits)
275 +#define kLenNumMidBits 3
276 +#define kLenNumMidSymbols (1 << kLenNumMidBits)
277 +#define kLenNumHighBits 8
278 +#define kLenNumHighSymbols (1 << kLenNumHighBits)
279 +
280 +#define LenChoice 0
281 +#define LenChoice2 (LenChoice + 1)
282 +#define LenLow (LenChoice2 + 1)
283 +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
284 +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
285 +#define kNumLenProbs (LenHigh + kLenNumHighSymbols) 
286 +
287 +
288 +#define kNumStates 12
289 +#define kNumLitStates 7
290 +
291 +#define kStartPosModelIndex 4
292 +#define kEndPosModelIndex 14
293 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
294 +
295 +#define kNumPosSlotBits 6
296 +#define kNumLenToPosStates 4
297 +
298 +#define kNumAlignBits 4
299 +#define kAlignTableSize (1 << kNumAlignBits)
300 +
301 +#define kMatchMinLen 2
302 +
303 +#define IsMatch 0
304 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
305 +#define IsRepG0 (IsRep + kNumStates)
306 +#define IsRepG1 (IsRepG0 + kNumStates)
307 +#define IsRepG2 (IsRepG1 + kNumStates)
308 +#define IsRep0Long (IsRepG2 + kNumStates)
309 +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
310 +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
311 +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
312 +#define LenCoder (Align + kAlignTableSize)
313 +#define RepLenCoder (LenCoder + kNumLenProbs)
314 +#define Literal (RepLenCoder + kNumLenProbs)
315 +
316 +#if Literal != LZMA_BASE_SIZE
317 +StopCompilingDueBUG
318 +#endif
319 +
320 +#ifdef _LZMA_OUT_READ
321 +
322 +typedef struct _LzmaVarState
323 +{
324 +  Byte *Buffer;
325 +  Byte *BufferLim;
326 +  UInt32 Range;
327 +  UInt32 Code;
328 +  #ifdef _LZMA_IN_CB
329 +  ILzmaInCallback *InCallback;
330 +  #endif
331 +  Byte *Dictionary;
332 +  UInt32 DictionarySize;
333 +  UInt32 DictionaryPos;
334 +  UInt32 GlobalPos;
335 +  UInt32 Reps[4];
336 +  int lc;
337 +  int lp;
338 +  int pb;
339 +  int State;
340 +  int RemainLen;
341 +  Byte TempDictionary[4];
342 +} LzmaVarState;
343 +
344 +int LzmaDecoderInit(
345 +    unsigned char *buffer, UInt32 bufferSize,
346 +    int lc, int lp, int pb,
347 +    unsigned char *dictionary, UInt32 dictionarySize,
348 +    #ifdef _LZMA_IN_CB
349 +    ILzmaInCallback *InCallback
350 +    #else
351 +    unsigned char *inStream, UInt32 inSize
352 +    #endif
353 +    )
354 +{
355 +  Byte *Buffer;
356 +  Byte *BufferLim;
357 +  UInt32 Range;
358 +  UInt32 Code;
359 +  LzmaVarState *vs = (LzmaVarState *)buffer;
360 +  CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
361 +  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
362 +  UInt32 i;
363 +  if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState))
364 +    return LZMA_RESULT_NOT_ENOUGH_MEM;
365 +  vs->Dictionary = dictionary;
366 +  vs->DictionarySize = dictionarySize;
367 +  vs->DictionaryPos = 0;
368 +  vs->GlobalPos = 0;
369 +  vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1;
370 +  vs->lc = lc;
371 +  vs->lp = lp;
372 +  vs->pb = pb;
373 +  vs->State = 0;
374 +  vs->RemainLen = 0;
375 +  dictionary[dictionarySize - 1] = 0;
376 +  for (i = 0; i < numProbs; i++)
377 +    p[i] = kBitModelTotal >> 1; 
378 +
379 +  #ifdef _LZMA_IN_CB
380 +  RC_INIT;
381 +  #else
382 +  RC_INIT(inStream, inSize);
383 +  #endif
384 +  vs->Buffer = Buffer;
385 +  vs->BufferLim = BufferLim;
386 +  vs->Range = Range;
387 +  vs->Code = Code;
388 +  #ifdef _LZMA_IN_CB
389 +  vs->InCallback = InCallback;
390 +  #endif
391 +
392 +  return LZMA_RESULT_OK;
393 +}
394 +
395 +int LzmaDecode(unsigned char *buffer, 
396 +    unsigned char *outStream, UInt32 outSize,
397 +    UInt32 *outSizeProcessed)
398 +{
399 +  LzmaVarState *vs = (LzmaVarState *)buffer;
400 +  Byte *Buffer = vs->Buffer;
401 +  Byte *BufferLim = vs->BufferLim;
402 +  UInt32 Range = vs->Range;
403 +  UInt32 Code = vs->Code;
404 +  #ifdef _LZMA_IN_CB
405 +  ILzmaInCallback *InCallback = vs->InCallback;
406 +  #endif
407 +  CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
408 +  int state = vs->State;
409 +  Byte previousByte;
410 +  UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
411 +  UInt32 nowPos = 0;
412 +  UInt32 posStateMask = (1 << (vs->pb)) - 1;
413 +  UInt32 literalPosMask = (1 << (vs->lp)) - 1;
414 +  int lc = vs->lc;
415 +  int len = vs->RemainLen;
416 +  UInt32 globalPos = vs->GlobalPos;
417 +
418 +  Byte *dictionary = vs->Dictionary;
419 +  UInt32 dictionarySize = vs->DictionarySize;
420 +  UInt32 dictionaryPos = vs->DictionaryPos;
421 +
422 +  Byte tempDictionary[4];
423 +  if (dictionarySize == 0)
424 +  {
425 +    dictionary = tempDictionary;
426 +    dictionarySize = 1;
427 +    tempDictionary[0] = vs->TempDictionary[0];
428 +  }
429 +
430 +  if (len == -1)
431 +  {
432 +    *outSizeProcessed = 0;
433 +    return LZMA_RESULT_OK;
434 +  }
435 +
436 +  while(len != 0 && nowPos < outSize)
437 +  {
438 +    UInt32 pos = dictionaryPos - rep0;
439 +    if (pos >= dictionarySize)
440 +      pos += dictionarySize;
441 +    outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
442 +    if (++dictionaryPos == dictionarySize)
443 +      dictionaryPos = 0;
444 +    len--;
445 +  }
446 +  if (dictionaryPos == 0)
447 +    previousByte = dictionary[dictionarySize - 1];
448 +  else
449 +    previousByte = dictionary[dictionaryPos - 1];
450 +#else
451 +
452 +int LzmaDecode(
453 +    Byte *buffer, UInt32 bufferSize,
454 +    int lc, int lp, int pb,
455 +    #ifdef _LZMA_IN_CB
456 +    ILzmaInCallback *InCallback,
457 +    #else
458 +    unsigned char *inStream, UInt32 inSize,
459 +    #endif
460 +    unsigned char *outStream, UInt32 outSize,
461 +    UInt32 *outSizeProcessed)
462 +{
463 +  UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
464 +  CProb *p = (CProb *)buffer;
465 +
466 +  UInt32 i;
467 +  int state = 0;
468 +  Byte previousByte = 0;
469 +  UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
470 +  UInt32 nowPos = 0;
471 +  UInt32 posStateMask = (1 << pb) - 1;
472 +  UInt32 literalPosMask = (1 << lp) - 1;
473 +  int len = 0;
474 +  
475 +  Byte *Buffer;
476 +  Byte *BufferLim;
477 +  UInt32 Range;
478 +  UInt32 Code;
479 +  
480 +  if (bufferSize < numProbs * sizeof(CProb))
481 +    return LZMA_RESULT_NOT_ENOUGH_MEM;
482 +  for (i = 0; i < numProbs; i++)
483 +    p[i] = kBitModelTotal >> 1;
484 +  
485 +
486 +  #ifdef _LZMA_IN_CB
487 +  RC_INIT;
488 +  #else
489 +  RC_INIT(inStream, inSize);
490 +  #endif
491 +#endif
492 +
493 +  *outSizeProcessed = 0;
494 +  while(nowPos < outSize)
495 +  {
496 +    CProb *prob;
497 +    UInt32 bound;
498 +    int posState = (int)(
499 +        (nowPos 
500 +        #ifdef _LZMA_OUT_READ
501 +        + globalPos
502 +        #endif
503 +        )
504 +        & posStateMask);
505 +
506 +    prob = p + IsMatch + (state << kNumPosBitsMax) + posState;
507 +    IfBit0(prob)
508 +    {
509 +      int symbol = 1;
510 +      UpdateBit0(prob)
511 +      prob = p + Literal + (LZMA_LIT_SIZE * 
512 +        (((
513 +        (nowPos 
514 +        #ifdef _LZMA_OUT_READ
515 +        + globalPos
516 +        #endif
517 +        )
518 +        & literalPosMask) << lc) + (previousByte >> (8 - lc))));
519 +
520 +      if (state >= kNumLitStates)
521 +      {
522 +        int matchByte;
523 +        #ifdef _LZMA_OUT_READ
524 +        UInt32 pos = dictionaryPos - rep0;
525 +        if (pos >= dictionarySize)
526 +          pos += dictionarySize;
527 +        matchByte = dictionary[pos];
528 +        #else
529 +        matchByte = outStream[nowPos - rep0];
530 +        #endif
531 +        do
532 +        {
533 +          int bit;
534 +          CProb *probLit;
535 +          matchByte <<= 1;
536 +          bit = (matchByte & 0x100);
537 +          probLit = prob + 0x100 + bit + symbol;
538 +          RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)
539 +        }
540 +        while (symbol < 0x100);
541 +      }
542 +      while (symbol < 0x100)
543 +      {
544 +        CProb *probLit = prob + symbol;
545 +        RC_GET_BIT(probLit, symbol)
546 +      }
547 +      previousByte = (Byte)symbol;
548 +
549 +      outStream[nowPos++] = previousByte;
550 +      #ifdef _LZMA_OUT_READ
551 +      dictionary[dictionaryPos] = previousByte;
552 +      if (++dictionaryPos == dictionarySize)
553 +        dictionaryPos = 0;
554 +      #endif
555 +      if (state < 4) state = 0;
556 +      else if (state < 10) state -= 3;
557 +      else state -= 6;
558 +    }
559 +    else             
560 +    {
561 +      UpdateBit1(prob);
562 +      prob = p + IsRep + state;
563 +      IfBit0(prob)
564 +      {
565 +        UpdateBit0(prob);
566 +        rep3 = rep2;
567 +        rep2 = rep1;
568 +        rep1 = rep0;
569 +        state = state < kNumLitStates ? 0 : 3;
570 +        prob = p + LenCoder;
571 +      }
572 +      else
573 +      {
574 +        UpdateBit1(prob);
575 +        prob = p + IsRepG0 + state;
576 +        IfBit0(prob)
577 +        {
578 +          UpdateBit0(prob);
579 +          prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;
580 +          IfBit0(prob)
581 +          {
582 +            #ifdef _LZMA_OUT_READ
583 +            UInt32 pos;
584 +            #endif
585 +            UpdateBit0(prob);
586 +            if (nowPos 
587 +                #ifdef _LZMA_OUT_READ
588 +                + globalPos
589 +                #endif
590 +                == 0)
591 +              return LZMA_RESULT_DATA_ERROR;
592 +            state = state < kNumLitStates ? 9 : 11;
593 +            #ifdef _LZMA_OUT_READ
594 +            pos = dictionaryPos - rep0;
595 +            if (pos >= dictionarySize)
596 +              pos += dictionarySize;
597 +            previousByte = dictionary[pos];
598 +            dictionary[dictionaryPos] = previousByte;
599 +            if (++dictionaryPos == dictionarySize)
600 +              dictionaryPos = 0;
601 +            #else
602 +            previousByte = outStream[nowPos - rep0];
603 +            #endif
604 +            outStream[nowPos++] = previousByte;
605 +            continue;
606 +          }
607 +          else
608 +          {
609 +            UpdateBit1(prob);
610 +          }
611 +        }
612 +        else
613 +        {
614 +          UInt32 distance;
615 +          UpdateBit1(prob);
616 +          prob = p + IsRepG1 + state;
617 +          IfBit0(prob)
618 +          {
619 +            UpdateBit0(prob);
620 +            distance = rep1;
621 +          }
622 +          else 
623 +          {
624 +            UpdateBit1(prob);
625 +            prob = p + IsRepG2 + state;
626 +            IfBit0(prob)
627 +            {
628 +              UpdateBit0(prob);
629 +              distance = rep2;
630 +            }
631 +            else
632 +            {
633 +              UpdateBit1(prob);
634 +              distance = rep3;
635 +              rep3 = rep2;
636 +            }
637 +            rep2 = rep1;
638 +          }
639 +          rep1 = rep0;
640 +          rep0 = distance;
641 +        }
642 +        state = state < kNumLitStates ? 8 : 11;
643 +        prob = p + RepLenCoder;
644 +      }
645 +      {
646 +        int numBits, offset;
647 +        CProb *probLen = prob + LenChoice;
648 +        IfBit0(probLen)
649 +        {
650 +          UpdateBit0(probLen);
651 +          probLen = prob + LenLow + (posState << kLenNumLowBits);
652 +          offset = 0;
653 +          numBits = kLenNumLowBits;
654 +        }
655 +        else
656 +        {
657 +          UpdateBit1(probLen);
658 +          probLen = prob + LenChoice2;
659 +          IfBit0(probLen)
660 +          {
661 +            UpdateBit0(probLen);
662 +            probLen = prob + LenMid + (posState << kLenNumMidBits);
663 +            offset = kLenNumLowSymbols;
664 +            numBits = kLenNumMidBits;
665 +          }
666 +          else
667 +          {
668 +            UpdateBit1(probLen);
669 +            probLen = prob + LenHigh;
670 +            offset = kLenNumLowSymbols + kLenNumMidSymbols;
671 +            numBits = kLenNumHighBits;
672 +          }
673 +        }
674 +        RangeDecoderBitTreeDecode(probLen, numBits, len);
675 +        len += offset;
676 +      }
677 +
678 +      if (state < 4)
679 +      {
680 +        int posSlot;
681 +        state += kNumLitStates;
682 +        prob = p + PosSlot +
683 +            ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << 
684 +            kNumPosSlotBits);
685 +        RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);
686 +        if (posSlot >= kStartPosModelIndex)
687 +        {
688 +          int numDirectBits = ((posSlot >> 1) - 1);
689 +          rep0 = (2 | ((UInt32)posSlot & 1));
690 +          if (posSlot < kEndPosModelIndex)
691 +          {
692 +            rep0 <<= numDirectBits;
693 +            prob = p + SpecPos + rep0 - posSlot - 1;
694 +          }
695 +          else
696 +          {
697 +            numDirectBits -= kNumAlignBits;
698 +            do
699 +            {
700 +              RC_NORMALIZE
701 +              Range >>= 1;
702 +              rep0 <<= 1;
703 +              if (Code >= Range)
704 +              {
705 +                Code -= Range;
706 +                rep0 |= 1;
707 +              }
708 +            }
709 +            while (--numDirectBits != 0);
710 +            prob = p + Align;
711 +            rep0 <<= kNumAlignBits;
712 +            numDirectBits = kNumAlignBits;
713 +          }
714 +          {
715 +            int i = 1;
716 +            int mi = 1;
717 +            do
718 +            {
719 +              CProb *prob3 = prob + mi;
720 +              RC_GET_BIT2(prob3, mi, ; , rep0 |= i);
721 +              i <<= 1;
722 +            }
723 +            while(--numDirectBits != 0);
724 +          }
725 +        }
726 +        else
727 +          rep0 = posSlot;
728 +        if (++rep0 == (UInt32)(0))
729 +        {
730 +          /* it's for stream version */
731 +          len = -1;
732 +          break;
733 +        }
734 +      }
735 +
736 +      len += kMatchMinLen;
737 +      if (rep0 > nowPos 
738 +        #ifdef _LZMA_OUT_READ
739 +        + globalPos || rep0 > dictionarySize
740 +        #endif
741 +        ) 
742 +        return LZMA_RESULT_DATA_ERROR;
743 +      do
744 +      {
745 +        #ifdef _LZMA_OUT_READ
746 +        UInt32 pos = dictionaryPos - rep0;
747 +        if (pos >= dictionarySize)
748 +          pos += dictionarySize;
749 +        previousByte = dictionary[pos];
750 +        dictionary[dictionaryPos] = previousByte;
751 +        if (++dictionaryPos == dictionarySize)
752 +          dictionaryPos = 0;
753 +        #else
754 +        previousByte = outStream[nowPos - rep0];
755 +        #endif
756 +        len--;
757 +        outStream[nowPos++] = previousByte;
758 +      }
759 +      while(len != 0 && nowPos < outSize);
760 +    }
761 +  }
762 +  RC_NORMALIZE;
763 +
764 +  #ifdef _LZMA_OUT_READ
765 +  vs->Buffer = Buffer;
766 +  vs->BufferLim = BufferLim;
767 +  vs->Range = Range;
768 +  vs->Code = Code;
769 +  vs->DictionaryPos = dictionaryPos;
770 +  vs->GlobalPos = globalPos + nowPos;
771 +  vs->Reps[0] = rep0;
772 +  vs->Reps[1] = rep1;
773 +  vs->Reps[2] = rep2;
774 +  vs->Reps[3] = rep3;
775 +  vs->State = state;
776 +  vs->RemainLen = len;
777 +  vs->TempDictionary[0] = tempDictionary[0];
778 +  #endif
779 +
780 +  *outSizeProcessed = nowPos;
781 +  return LZMA_RESULT_OK;
782 +}
783 --- busybox-20050614.orig/archival/libunarchive/LzmaDecode.h    1970-01-01 01:00:00.000000000 +0100
784 +++ busybox-20050614/archival/libunarchive/LzmaDecode.h 2005-06-15 02:14:03.000000000 +0200
785 @@ -0,0 +1,100 @@
786 +/* 
787 +  LzmaDecode.h
788 +  LZMA Decoder interface
789 +
790 +  LZMA SDK 4.16 Copyright (c) 1999-2005 Igor Pavlov (2005-03-18)
791 +  http://www.7-zip.org/
792 +
793 +  LZMA SDK is licensed under two licenses:
794 +  1) GNU Lesser General Public License (GNU LGPL)
795 +  2) Common Public License (CPL)
796 +  It means that you can select one of these two licenses and 
797 +  follow rules of that license.
798 +
799 +  SPECIAL EXCEPTION:
800 +  Igor Pavlov, as the author of this code, expressly permits you to 
801 +  statically or dynamically link your code (or bind by name) to the 
802 +  interfaces of this file without subjecting your linked code to the 
803 +  terms of the CPL or GNU LGPL. Any modifications or additions 
804 +  to this file, however, are subject to the LGPL or CPL terms.
805 +*/
806 +
807 +#ifndef __LZMADECODE_H
808 +#define __LZMADECODE_H
809 +
810 +#define _LZMA_IN_CB
811 +/* Use callback for input data */
812 +
813 +#define _LZMA_OUT_READ 
814 +/* Use read function for output data */
815 +
816 +#define _LZMA_PROB32
817 +/* It can increase speed on some 32-bit CPUs, 
818 +   but memory usage will be doubled in that case */
819 +
820 +#define _LZMA_LOC_OPT 
821 +/* Enable local speed optimizations inside code */
822 +
823 +#ifndef UInt32
824 +#ifdef _LZMA_UINT32_IS_ULONG
825 +#define UInt32 unsigned long
826 +#else
827 +#define UInt32 unsigned int
828 +#endif
829 +#endif
830 +
831 +#ifdef _LZMA_PROB32
832 +#define CProb UInt32
833 +#else
834 +#define CProb unsigned short
835 +#endif
836 +
837 +#define LZMA_RESULT_OK 0
838 +#define LZMA_RESULT_DATA_ERROR 1
839 +#define LZMA_RESULT_NOT_ENOUGH_MEM 2
840 +
841 +#ifdef _LZMA_IN_CB
842 +typedef struct _ILzmaInCallback
843 +{
844 +  int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize);
845 +} ILzmaInCallback;
846 +#endif
847 +
848 +#define LZMA_BASE_SIZE 1846
849 +#define LZMA_LIT_SIZE 768
850 +
851 +/* 
852 +bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb)
853 +bufferSize += 100 in case of _LZMA_OUT_READ
854 +by default CProb is unsigned short, 
855 +but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int)
856 +*/
857 +
858 +#ifdef _LZMA_OUT_READ
859 +int LzmaDecoderInit(
860 +    unsigned char *buffer, UInt32 bufferSize,
861 +    int lc, int lp, int pb,
862 +    unsigned char *dictionary, UInt32 dictionarySize,
863 +  #ifdef _LZMA_IN_CB
864 +    ILzmaInCallback *inCallback
865 +  #else
866 +    unsigned char *inStream, UInt32 inSize
867 +  #endif
868 +);
869 +#endif
870 +
871 +int LzmaDecode(
872 +    unsigned char *buffer, 
873 +  #ifndef _LZMA_OUT_READ
874 +    UInt32 bufferSize,
875 +    int lc, int lp, int pb,
876 +  #ifdef _LZMA_IN_CB
877 +    ILzmaInCallback *inCallback,
878 +  #else
879 +    unsigned char *inStream, UInt32 inSize,
880 +  #endif
881 +  #endif
882 +    unsigned char *outStream, UInt32 outSize,
883 +    UInt32 *outSizeProcessed);
884 +
885 +#endif
886 --- busybox-20050614.orig/archival/Config.in    2005-06-14 08:20:08.000000000 +0200
887 +++ busybox-20050614/archival/Config.in 2005-06-15 01:31:10.000000000 +0200
888 @@ -121,6 +121,12 @@
889           gzip is used to compress files.
890           It's probably the most widely used UNIX compression program.
891  
892 +config CONFIG_LZMACAT
893 +       bool "lzmacat"
894 +       default n
895 +       help
896 +         lzmacat decompresses a given file to STUOUT
897 +
898  config CONFIG_RPM2CPIO
899         bool "rpm2cpio"
900         default n
901 --- busybox-20050614.orig/archival/Makefile.in  2005-06-14 08:20:08.000000000 +0200
902 +++ busybox-20050614/archival/Makefile.in       2005-06-15 01:31:10.000000000 +0200
903 @@ -32,6 +32,7 @@
904  ARCHIVAL-$(CONFIG_DPKG_DEB)    += dpkg_deb.o
905  ARCHIVAL-$(CONFIG_GUNZIP)      += gunzip.o
906  ARCHIVAL-$(CONFIG_GZIP)                += gzip.o
907 +ARCHIVAL-$(CONFIG_LZMACAT)     += lzmacat.o
908  ARCHIVAL-$(CONFIG_RPM2CPIO)    += rpm2cpio.o
909  ARCHIVAL-$(CONFIG_RPM)         += rpm.o
910  ARCHIVAL-$(CONFIG_TAR)         += tar.o
911
912 --- busybox-20050614.orig/archival/libunarchive/Makefile.in     2005-06-14 08:20:08.000000000 +0200
913 +++ busybox-20050614/archival/libunarchive/Makefile.in  2005-06-15 01:31:10.000000000 +0200
914 @@ -64,6 +64,7 @@
915  LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_GZ) += $(GUNZIP_FILES) get_header_tar_gz.o
916  LIBUNARCHIVE-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
917  LIBUNARCHIVE-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
918 +LIBUNARCHIVE-$(CONFIG_LZMACAT) += LzmaDecode.o
919  LIBUNARCHIVE-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
920  LIBUNARCHIVE-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
921  LIBUNARCHIVE-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
922
923 --- busybox-20050614.orig/include/applets.h     2005-06-14 08:20:18.000000000 +0200
924 +++ busybox-20050614/include/applets.h  2005-06-15 01:31:11.000000000 +0200
925 @@ -383,6 +383,9 @@
926  #ifdef CONFIG_LSMOD
927         APPLET(lsmod, lsmod_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
928  #endif
929 +#ifdef CONFIG_LZMACAT
930 +       APPLET(lzmacat, lzmacat_main, _BB_DIR_BIN, _BB_SUID_NEVER)
931 +#endif
932  #ifdef CONFIG_MAKEDEVS
933         APPLET(makedevs, makedevs_main, _BB_DIR_SBIN, _BB_SUID_NEVER)
934  #endif
935 --- busybox-20050614.orig/include/usage.h       2005-06-14 08:20:18.000000000 +0200
936 +++ busybox-20050614/include/usage.h    2005-06-15 01:33:02.000000000 +0200
937 @@ -1622,6 +1622,11 @@
938  #define lsmod_full_usage \
939         "List the currently loaded kernel modules."
940  
941 +#define lzmacat_trivial_usage \
942 +       "[FILE]"
943 +#define lzmacat_full_usage \
944 +       "Decompresses [FILE] to STDOUT."
945 +
946  #define makedevs_trivial_usage \
947         "NAME TYPE MAJOR MINOR FIRST LAST [s]"
948  #define makedevs_full_usage \
This page took 0.247928 seconds and 3 git commands to generate.