94#define MAXCODES (MAXLCODES+MAXDCODES)
105 const unsigned char *
in;
132 while (s->
bitcnt < need) {
144 return (
int)(val & ((1L << need) - 1));
243 code = first = index = 0;
276 code = first = index = 0;
350 for (symbol = 0; symbol < n; symbol++)
351 (h->
count[length[symbol]])++;
352 if (h->
count[0] == n)
373 for (symbol = 0; symbol < n; symbol++)
374 if (length[symbol] != 0)
375 h->
symbol[offs[length[symbol]]++] = symbol;
438 const struct huffman *distcode)
443 static const short lens[29] = {
444 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
445 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258};
446 static const short lext[29] = {
447 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
448 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
449 static const short dists[30] = {
450 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
451 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
452 8193, 12289, 16385, 24577};
453 static const short dext[30] = {
454 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
455 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
460 symbol =
decode(s, lencode);
472 else if (symbol > 256) {
477 len = lens[symbol] +
bits(s, lext[symbol]);
480 symbol =
decode(s, distcode);
483 dist = dists[symbol] +
bits(s, dext[symbol]);
484#ifndef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
495#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
506 }
while (symbol != 256);
538 static int virgin = 1;
541 static struct huffman lencode, distcode;
549 lencode.
count = lencnt;
551 distcode.
count = distcnt;
552 distcode.
symbol = distsym;
575 return codes(s, &lencode, &distcode);
667 int nlen, ndist, ncode;
673 struct huffman lencode, distcode;
674 static const short order[19] =
675 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
678 lencode.
count = lencnt;
680 distcode.
count = distcnt;
681 distcode.
symbol = distsym;
684 nlen =
bits(s, 5) + 257;
685 ndist =
bits(s, 5) + 1;
686 ncode =
bits(s, 4) + 4;
691 for (index = 0; index < ncode; index++)
692 lengths[order[index]] =
bits(s, 3);
693 for (; index < 19; index++)
694 lengths[order[index]] = 0;
703 while (index < nlen + ndist) {
711 lengths[index++] =
symbol;
717 len = lengths[index - 1];
724 if (index +
symbol > nlen + ndist)
727 lengths[index++] =
len;
732 if (lengths[256] == 0)
746 return codes(s, &lencode, &distcode);
794 unsigned long *destlen,
795 const unsigned char *source,
796 unsigned long *sourcelen)
809 s.
inlen = *sourcelen;
815 if (setjmp(s.
env) != 0)
837 *sourcelen = s.
incnt;
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
int construct(struct huffman *h, const short *length, int n)
int puff(unsigned char *dest, unsigned long *destlen, const unsigned char *source, unsigned long *sourcelen)
int stored(struct state *s)
int decode(struct state *s, const struct huffman *h)
int dynamic(struct state *s)
int codes(struct state *s, const struct huffman *lencode, const struct huffman *distcode)
int fixed(struct state *s)
int bits(struct state *s, int need)
unsigned char out[MAXWIN]