Lines Matching refs:bd

116 static unsigned int INIT get_bits(struct bunzip_data *bd, char bits_wanted)  in get_bits()  argument
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()
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()
156 static int INIT get_next_block(struct bunzip_data *bd) in get_next_block() argument
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()
175 i = get_bits(bd, 24); in get_next_block()
176 j = get_bits(bd, 24); in get_next_block()
177 bd->headerCRC = get_bits(bd, 32); in get_next_block()
185 if (get_bits(bd, 1)) in get_next_block()
187 origPtr = get_bits(bd, 24); in get_next_block()
195 t = get_bits(bd, 16); in get_next_block()
199 k = get_bits(bd, 16); in get_next_block()
206 groupCount = get_bits(bd, 3); in get_next_block()
214 nSelectors = get_bits(bd, 15); in get_next_block()
221 for (j = 0; get_bits(bd, 1); j++) in get_next_block()
247 t = get_bits(bd, 5)-1; in get_next_block()
259 k = get_bits(bd, 2); in get_next_block()
261 bd->inbufBitCount++; in get_next_block()
297 hufGroup = bd->groups+j; in get_next_block()
365 hufGroup = bd->groups+selectors[selector++]; in get_next_block()
381 while (bd->inbufBitCount < hufGroup->maxLen) { in get_next_block()
382 if (bd->inbufPos == bd->inbufCount) { in get_next_block()
383 j = get_bits(bd, hufGroup->maxLen); in get_next_block()
386 bd->inbufBits = in get_next_block()
387 (bd->inbufBits << 8)|bd->inbuf[bd->inbufPos++]; in get_next_block()
388 bd->inbufBitCount += 8; in get_next_block()
390 bd->inbufBitCount -= hufGroup->maxLen; in get_next_block()
391 j = (bd->inbufBits >> bd->inbufBitCount)& in get_next_block()
399 bd->inbufBitCount += (hufGroup->maxLen - i); in get_next_block()
507 bd->writePos = dbuf[origPtr]; in get_next_block()
508 bd->writeCurrent = (unsigned char)(bd->writePos&0xff); in get_next_block()
509 bd->writePos >>= 8; in get_next_block()
510 bd->writeRunCountdown = 5; in get_next_block()
512 bd->writeCount = dbufCount; in get_next_block()
524 static int INIT read_bunzip(struct bunzip_data *bd, char *outbuf, int len) in read_bunzip() argument
530 if (bd->writeCount < 0) in read_bunzip()
531 return bd->writeCount; in read_bunzip()
534 dbuf = bd->dbuf; in read_bunzip()
535 pos = bd->writePos; in read_bunzip()
536 xcurrent = bd->writeCurrent; in read_bunzip()
542 if (bd->writeCopies) { in read_bunzip()
544 --bd->writeCopies; in read_bunzip()
550 bd->writePos = pos; in read_bunzip()
551 bd->writeCurrent = xcurrent; in read_bunzip()
552 bd->writeCopies++; in read_bunzip()
557 bd->writeCRC = (((bd->writeCRC) << 8) in read_bunzip()
558 ^bd->crc32Table[((bd->writeCRC) >> 24) in read_bunzip()
562 if (bd->writeCopies) { in read_bunzip()
563 --bd->writeCopies; in read_bunzip()
567 if (!bd->writeCount--) in read_bunzip()
579 if (--bd->writeRunCountdown) { in read_bunzip()
581 bd->writeRunCountdown = 4; in read_bunzip()
585 bd->writeCopies = xcurrent; in read_bunzip()
587 bd->writeRunCountdown = 5; in read_bunzip()
590 if (!bd->writeCopies) in read_bunzip()
594 --bd->writeCopies; in read_bunzip()
598 bd->writeCRC = ~bd->writeCRC; in read_bunzip()
599 bd->totalCRC = ((bd->totalCRC << 1) | in read_bunzip()
600 (bd->totalCRC >> 31)) ^ bd->writeCRC; in read_bunzip()
602 if (bd->writeCRC != bd->headerCRC) { in read_bunzip()
603 bd->totalCRC = bd->headerCRC+1; in read_bunzip()
611 previous = get_next_block(bd); in read_bunzip()
613 bd->writeCount = previous; in read_bunzip()
616 bd->writeCRC = 0xffffffffUL; in read_bunzip()
617 pos = bd->writePos; in read_bunzip()
618 xcurrent = bd->writeCurrent; in read_bunzip()
633 struct bunzip_data *bd; in start_bunzip() local
643 bd = *bdp = malloc(i); in start_bunzip()
644 if (!bd) in start_bunzip()
646 memset(bd, 0, sizeof(struct bunzip_data)); in start_bunzip()
648 bd->inbuf = inbuf; in start_bunzip()
649 bd->inbufCount = len; in start_bunzip()
651 bd->fill = fill; in start_bunzip()
653 bd->fill = nofill; in start_bunzip()
660 bd->crc32Table[i] = c; in start_bunzip()
664 i = get_bits(bd, 32); in start_bunzip()
670 bd->dbufSize = 100000*(i-BZh0); in start_bunzip()
672 bd->dbuf = large_malloc(bd->dbufSize * sizeof(int)); in start_bunzip()
673 if (!bd->dbuf) in start_bunzip()
687 struct bunzip_data *bd; in bunzip2() local
707 i = start_bunzip(&bd, inbuf, len, fill); in bunzip2()
710 i = read_bunzip(bd, outbuf, BZIP2_IOBUF_SIZE); in bunzip2()
724 if (bd->headerCRC != bd->totalCRC) in bunzip2()
731 if (!bd) in bunzip2()
733 if (bd->dbuf) in bunzip2()
734 large_free(bd->dbuf); in bunzip2()
736 *pos = bd->inbufPos; in bunzip2()
737 free(bd); in bunzip2()