94 #define MAXCODES (MAXLCODES+MAXDCODES)
105 const unsigned char *
in;
132 while (
s->bitcnt < need) {
133 if (
s->incnt ==
s->inlen)
135 val |= (
long)(
s->in[
s->incnt++]) <<
s->bitcnt;
140 s->bitbuf = (
int)(
val >> need);
144 return (
int)(
val & ((1L << need) - 1));
173 if (
s->incnt + 4 >
s->inlen)
175 len =
s->in[
s->incnt++];
176 len |=
s->in[
s->incnt++] << 8;
177 if (
s->in[
s->incnt++] != (~
len & 0xff) ||
178 s->in[
s->incnt++] != ((~
len >> 8) & 0xff))
182 if (
s->incnt +
len >
s->inlen)
185 if (
s->outcnt +
len >
s->outlen)
188 s->out[
s->outcnt++] =
s->in[
s->incnt++];
243 code = first = index = 0;
248 return h->symbol[index + (
code - first)];
276 code = first = index = 0;
286 s->bitcnt = (
s->bitcnt -
len) & 7;
287 return h->symbol[index + (
code - first)];
298 if (
s->incnt ==
s->inlen)
300 bitbuf =
s->in[
s->incnt++];
350 for (symbol = 0; symbol <
n; symbol++)
352 if (
h->count[0] ==
n)
359 left -=
h->count[
len];
373 for (symbol = 0; symbol <
n; symbol++)
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,
466 if (
s->outcnt ==
s->outlen)
468 s->out[
s->outcnt] = symbol;
472 else if (symbol > 256) {
477 len = lens[symbol] +
bits(
s, lext[symbol]);
483 dist = dists[symbol] +
bits(
s, dext[symbol]);
484 #ifndef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
485 if (dist >
s->outcnt)
491 if (
s->outcnt +
len >
s->outlen)
495 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
499 s->out[
s->outcnt - dist];
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;
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags long
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
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)