Lines Matching +full:len +full:- +full:or +full:- +full:limit
20 the Burrows-Wheeler transformation. Much of that time is delay
25 non-profit hospice organization in the name of the woman I loved, who
32 Lafayette, LA 70503-3240
34 Phone (337) 232-1234 or 1-800-738-2226
35 Fax (337) 232-1297
70 #define RETVAL_LAST_BLOCK (-1)
71 #define RETVAL_NOT_BZIP_DATA (-2)
72 #define RETVAL_UNEXPECTED_INPUT_EOF (-3)
73 #define RETVAL_UNEXPECTED_OUTPUT_EOF (-4)
74 #define RETVAL_DATA_ERROR (-5)
75 #define RETVAL_OUT_OF_MEMORY (-6)
76 #define RETVAL_OBSOLETE_INPUT (-7)
83 /* We have an extra slot at the end of limit[] for a sentinel value. */
84 int limit[MAX_HUFCODE_BITS+1]; member
108 int io_error; /* non-zero if we have IO error */
123 while (bd->inbufBitCount < bits_wanted) { in get_bits()
126 if (bd->inbufPos == bd->inbufCount) { in get_bits()
127 if (bd->io_error) in get_bits()
129 bd->inbufCount = bd->fill(bd->inbuf, BZIP2_IOBUF_SIZE); in get_bits()
130 if (bd->inbufCount <= 0) { in get_bits()
131 bd->io_error = RETVAL_UNEXPECTED_INPUT_EOF; in get_bits()
134 bd->inbufPos = 0; in get_bits()
136 /* Avoid 32-bit overflow (dump bit buffer to top of output) */ in get_bits()
137 if (bd->inbufBitCount >= 24) { in get_bits()
138 bits = bd->inbufBits&((1 << bd->inbufBitCount)-1); in get_bits()
139 bits_wanted -= bd->inbufBitCount; in get_bits()
141 bd->inbufBitCount = 0; in get_bits()
144 bd->inbufBits = (bd->inbufBits << 8)|bd->inbuf[bd->inbufPos++]; in get_bits()
145 bd->inbufBitCount += 8; in get_bits()
148 bd->inbufBitCount -= bits_wanted; in get_bits()
149 bits |= (bd->inbufBits >> bd->inbufBitCount)&((1 << bits_wanted)-1); in get_bits()
154 /* Unpacks the next block and sets up for the inverse burrows-wheeler step. */
160 int *limit = NULL; in get_next_block() local
166 dbuf = bd->dbuf; in get_next_block()
167 dbufSize = bd->dbufSize; in get_next_block()
168 selectors = bd->selectors; in get_next_block()
169 byteCount = bd->byteCount; in get_next_block()
170 symToByte = bd->symToByte; in get_next_block()
171 mtfSymbol = bd->mtfSymbol; in get_next_block()
177 bd->headerCRC = get_bits(bd, 32); in get_next_block()
183 There was some code for this in busybox 1.0.0-pre3, but nobody ever in get_next_block()
198 if (t&(1 << (15-i))) { in get_next_block()
201 if (k&(1 << (15-j))) in get_next_block()
226 for (; j; j--) in get_next_block()
227 mtfSymbol[j] = mtfSymbol[j-1]; in get_next_block()
246 t = get_bits(bd, 5)-1; in get_next_block()
249 if (((unsigned)t) > (MAX_HUFCODE_BITS-1)) in get_next_block()
254 increment or decrement the value. in get_next_block()
260 bd->inbufBitCount++; in get_next_block()
265 t += (((k+1)&2)-1); in get_next_block()
267 /* Correct for the initial -1, to get the in get_next_block()
281 /* Calculate permute[], base[], and limit[] tables from in get_next_block()
290 * limit[] indicates the largest numerical value a in get_next_block()
293 * code with a value > limit[length] needs another in get_next_block()
296 hufGroup = bd->groups+j; in get_next_block()
297 hufGroup->minLen = minLen; in get_next_block()
298 hufGroup->maxLen = maxLen; in get_next_block()
300 adjust the base and limit array pointers so we're in get_next_block()
303 base = hufGroup->base-1; in get_next_block()
304 limit = hufGroup->limit-1; in get_next_block()
306 * temp[] and limit[]. */ in get_next_block()
309 temp[i] = limit[i] = 0; in get_next_block()
312 hufGroup->permute[pp++] = t; in get_next_block()
317 /* Calculate limit[] (the largest symbol-coding value in get_next_block()
318 *at each bit length, which is (previous limit << in get_next_block()
320 *symbols to ignore at each bit length, which is limit in get_next_block()
333 to-be-ignored bits to 1 so they don't in get_next_block()
334 affect the value > limit[length] in get_next_block()
336 limit[i] = (pp << (maxLen - i)) - 1; in get_next_block()
338 base[i+1] = pp-(t += temp[i]); in get_next_block()
340 limit[maxLen+1] = INT_MAX; /* Sentinel value for in get_next_block()
342 limit[maxLen] = pp+temp[maxLen]-1; in get_next_block()
360 if (!(symCount--)) { in get_next_block()
361 symCount = GROUP_SIZE-1; in get_next_block()
364 hufGroup = bd->groups+selectors[selector++]; in get_next_block()
365 base = hufGroup->base-1; in get_next_block()
366 limit = hufGroup->limit-1; in get_next_block()
368 /* Read next Huffman-coded symbol. */ in get_next_block()
378 equivalent to j = get_bits(bd, hufGroup->maxLen); in get_next_block()
380 while (bd->inbufBitCount < hufGroup->maxLen) { in get_next_block()
381 if (bd->inbufPos == bd->inbufCount) { in get_next_block()
382 j = get_bits(bd, hufGroup->maxLen); in get_next_block()
385 bd->inbufBits = in get_next_block()
386 (bd->inbufBits << 8)|bd->inbuf[bd->inbufPos++]; in get_next_block()
387 bd->inbufBitCount += 8; in get_next_block()
389 bd->inbufBitCount -= hufGroup->maxLen; in get_next_block()
390 j = (bd->inbufBits >> bd->inbufBitCount)& in get_next_block()
391 ((1 << hufGroup->maxLen)-1); in get_next_block()
395 i = hufGroup->minLen; in get_next_block()
396 while (j > limit[i]) in get_next_block()
398 bd->inbufBitCount += (hufGroup->maxLen - i); in get_next_block()
400 if ((i > hufGroup->maxLen) in get_next_block()
401 || (((unsigned)(j = (j>>(hufGroup->maxLen-i))-base[i])) in get_next_block()
404 nextSym = hufGroup->permute[j]; in get_next_block()
406 either a new literal byte, or a repeated run of the in get_next_block()
410 if (((unsigned)nextSym) <= SYMBOL_RUNB) { /* RUNA or RUNB */ in get_next_block()
418 or-ing 0 or 1 at each bit position, add 1 in get_next_block()
419 or 2 instead. For example, 1011 is 1 << 0 in get_next_block()
423 or 0/1 method (except all bits 0, which in get_next_block()
433 /* When we hit the first non-run symbol after a run, in get_next_block()
446 while (t--) in get_next_block()
455 found. (Note that the result can't be -1 or 0, in get_next_block()
460 non-literal nextSym values equals -1.) */ in get_next_block()
463 i = nextSym - 1; in get_next_block()
471 mtfSymbol[i] = mtfSymbol[i-1]; in get_next_block()
472 } while (--i); in get_next_block()
479 /* At this point, we've read all the Huffman-coded symbols in get_next_block()
483 Burrows-Wheeler transform on dbuf. See in get_next_block()
486 /* Turn byteCount into cumulative occurrence counts of 0 to n-1. */ in get_next_block()
506 bd->writePos = dbuf[origPtr]; in get_next_block()
507 bd->writeCurrent = (unsigned char)(bd->writePos&0xff); in get_next_block()
508 bd->writePos >>= 8; in get_next_block()
509 bd->writeRunCountdown = 5; in get_next_block()
511 bd->writeCount = dbufCount; in get_next_block()
516 /* Undo burrows-wheeler transform on intermediate buffer to produce output.
517 If start_bunzip was initialized with out_fd =-1, then up to len bytes of
518 data are written to outbuf. Return value is number of bytes written or
519 error (all errors are negative numbers). If out_fd!=-1, outbuf and len
520 are ignored, data is written to out_fd and return is RETVAL_OK or error.
523 static int INIT read_bunzip(struct bunzip_data *bd, char *outbuf, int len) in read_bunzip() argument
529 if (bd->writeCount < 0) in read_bunzip()
530 return bd->writeCount; in read_bunzip()
533 dbuf = bd->dbuf; in read_bunzip()
534 pos = bd->writePos; in read_bunzip()
535 xcurrent = bd->writeCurrent; in read_bunzip()
539 Huffman-decoded a block into the intermediate buffer yet). */ in read_bunzip()
541 if (bd->writeCopies) { in read_bunzip()
543 --bd->writeCopies; in read_bunzip()
548 if (gotcount >= len) { in read_bunzip()
549 bd->writePos = pos; in read_bunzip()
550 bd->writeCurrent = xcurrent; in read_bunzip()
551 bd->writeCopies++; in read_bunzip()
552 return len; in read_bunzip()
556 bd->writeCRC = (((bd->writeCRC) << 8) in read_bunzip()
557 ^bd->crc32Table[((bd->writeCRC) >> 24) in read_bunzip()
561 if (bd->writeCopies) { in read_bunzip()
562 --bd->writeCopies; in read_bunzip()
566 if (!bd->writeCount--) in read_bunzip()
569 * Burrows-Wheeler transform */ in read_bunzip()
577 testing for non-zero is faster */ in read_bunzip()
578 if (--bd->writeRunCountdown) { in read_bunzip()
580 bd->writeRunCountdown = 4; in read_bunzip()
584 bd->writeCopies = xcurrent; in read_bunzip()
586 bd->writeRunCountdown = 5; in read_bunzip()
589 if (!bd->writeCopies) in read_bunzip()
593 --bd->writeCopies; in read_bunzip()
597 bd->writeCRC = ~bd->writeCRC; in read_bunzip()
598 bd->totalCRC = ((bd->totalCRC << 1) | in read_bunzip()
599 (bd->totalCRC >> 31)) ^ bd->writeCRC; in read_bunzip()
601 if (bd->writeCRC != bd->headerCRC) { in read_bunzip()
602 bd->totalCRC = bd->headerCRC+1; in read_bunzip()
607 /* Refill the intermediate buffer by Huffman-decoding next in read_bunzip()
612 bd->writeCount = previous; in read_bunzip()
615 bd->writeCRC = 0xffffffffUL; in read_bunzip()
616 pos = bd->writePos; in read_bunzip()
617 xcurrent = bd->writeCurrent; in read_bunzip()
621 static long INIT nofill(void *buf, unsigned long len) in nofill() argument
623 return -1; in nofill()
626 /* Allocate the structure, read file header. If in_fd ==-1, inbuf must contain
627 a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are
629 static int INIT start_bunzip(struct bunzip_data **bdp, void *inbuf, long len, in start_bunzip() argument
647 bd->inbuf = inbuf; in start_bunzip()
648 bd->inbufCount = len; in start_bunzip()
650 bd->fill = fill; in start_bunzip()
652 bd->fill = nofill; in start_bunzip()
657 for (j = 8; j; j--) in start_bunzip()
659 bd->crc32Table[i] = c; in start_bunzip()
662 /* Ensure that file starts with "BZh['1'-'9']." */ in start_bunzip()
664 if (((unsigned int)(i-BZh0-1)) >= 9) in start_bunzip()
667 /* Fourth byte (ascii '1'-'9'), indicates block size in units of 100k of in start_bunzip()
669 bd->dbufSize = 100000*(i-BZh0); in start_bunzip()
671 bd->dbuf = large_malloc(bd->dbufSize * sizeof(int)); in start_bunzip()
672 if (!bd->dbuf) in start_bunzip()
679 STATIC int INIT bunzip2(unsigned char *buf, long len, in bunzip2() argument
687 int i = -1; in bunzip2()
706 i = start_bunzip(&bd, inbuf, len, fill); in bunzip2()
723 if (bd->headerCRC != bd->totalCRC) in bunzip2()
732 if (bd->dbuf) in bunzip2()
733 large_free(bd->dbuf); in bunzip2()
735 *pos = bd->inbufPos; in bunzip2()
747 STATIC int INIT __decompress(unsigned char *buf, long len, in __decompress() argument
754 return bunzip2(buf, len - 4, fill, flush, outbuf, pos, error); in __decompress()