78 while (s->bitcnt < need) {
80 s->left = s->infun(s->inhow, &(s->in));
81 if (s->left == 0) longjmp(s->env, 1);
83 val |= (
int)(*(s->in)++) << s->bitcnt;
89 s->bitbuf = val >> need;
93 return val & ((1 << need) - 1);
147 code |= (bitbuf & 1) ^ 1;
152 s->bitcnt = (s->bitcnt -
len) & 7;
162 if (left == 0)
break;
164 s->left = s->infun(s->inhow, &(s->in));
165 if (s->left == 0) longjmp(s->env, 1);
169 if (left > 8) left = 8;
203 left = (
len >> 4) + 1;
214 for (symbol = 0; symbol <
n; symbol++)
215 (h->count[
length[symbol]])++;
216 if (h->count[0] ==
n)
223 left -= h->count[
len];
224 if (left < 0)
return left;
230 offs[
len + 1] = offs[
len] + h->count[
len];
236 for (symbol = 0; symbol <
n; symbol++)
238 h->symbol[offs[
length[symbol]]++] = symbol;
291 static int virgin = 1;
292 static short litcnt[
MAXBITS+1], litsym[256];
293 static short lencnt[
MAXBITS+1], lensym[16];
294 static short distcnt[
MAXBITS+1], distsym[64];
295 static struct huffman litcode = {litcnt, litsym};
296 static struct huffman lencode = {lencnt, lensym};
297 static struct huffman distcode = {distcnt, distsym};
299 static const unsigned char litlen[] = {
300 11, 124, 8, 7, 28, 7, 188, 13, 76, 4, 10, 8, 12, 10, 12, 10, 8, 23, 8,
301 9, 7, 6, 7, 8, 7, 6, 55, 8, 23, 24, 12, 11, 7, 9, 11, 12, 6, 7, 22, 5,
302 7, 24, 6, 11, 9, 6, 7, 22, 7, 11, 38, 7, 9, 8, 25, 11, 8, 11, 9, 12,
303 8, 12, 5, 38, 5, 38, 5, 11, 7, 5, 6, 21, 6, 10, 53, 8, 7, 24, 10, 27,
304 44, 253, 253, 253, 252, 252, 252, 13, 12, 45, 12, 45, 12, 61, 12, 45,
307 static const unsigned char lenlen[] = {2, 35, 36, 53, 38, 23};
309 static const unsigned char distlen[] = {2, 20, 53, 230, 247, 151, 248};
310 static const short base[16] = {
311 3, 2, 4, 5, 6, 7, 8, 9, 10, 12, 16, 24, 40, 72, 136, 264};
312 static const char extra[16] = {
313 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8};
317 construct(&litcode, litlen,
sizeof(litlen));
318 construct(&lencode, lenlen,
sizeof(lenlen));
319 construct(&distcode, distlen,
sizeof(distlen));
325 if (lit > 1)
return -1;
327 if (dict < 4 || dict > 6)
return -2;
335 if (
len == 519)
break;
342 if (s->first && dist > s->next)
347 to = s->out + s->next;
350 if (s->next < dist) {
362 if (s->outfun(s->outhow, s->out, s->next))
return 1;
371 s->out[s->next++] =
symbol;
373 if (s->outfun(s->outhow, s->out, s->next))
return 1;
384 unsigned *left,
unsigned char **
in)
408 if (setjmp(s.env) != 0)
417 *
in = s.left ? s.in : NULL;
420 if (
err != 1 && s.next && s.outfun(s.outhow, s.out, s.next) &&
err == 0)
434 static unsigned char hold[
CHUNK];
437 return fread(hold, 1,
CHUNK, (
FILE *)how);
440 local int outf(
void *how,
unsigned char *
buf,
unsigned len)
455 fprintf(
stderr,
"blast error: %d\n",
ret);
458 while (getchar() != EOF)
461 fprintf(
stderr,
"blast warning: %u unused bytes of input\n",
left);