74 while (s->bitcnt < need) {
76 s->left = s->infun(s->inhow, &(s->in));
77 if (s->left == 0) longjmp(s->env, 1);
79 val |= (
int)(*(s->in)++) << s->bitcnt;
85 s->bitbuf = val >> need;
89 return val & ((1 << need) - 1);
138 code = first = index = 0;
143 code |= (bitbuf & 1) ^ 1;
146 if (code < first + count) {
148 s->bitcnt = (s->bitcnt -
len) & 7;
149 return h->symbol[index + (code -
first)];
158 if (left == 0)
break;
160 s->left = s->infun(s->inhow, &(s->in));
161 if (s->left == 0) longjmp(s->env, 1);
165 if (left > 8) left = 8;
199 left = (len >> 4) + 1;
202 length[symbol++] =
len;
208 for (len = 0; len <=
MAXBITS; len++)
210 for (symbol = 0; symbol <
n; symbol++)
211 (h->count[length[symbol]])++;
212 if (h->count[0] == n)
217 for (len = 1; len <=
MAXBITS; len++) {
219 left -= h->count[
len];
220 if (left < 0)
return left;
225 for (len = 1; len <
MAXBITS; len++)
226 offs[len + 1] = offs[len] + h->count[len];
232 for (symbol = 0; symbol <
n; symbol++)
233 if (length[symbol] != 0)
234 h->symbol[offs[length[symbol]]++] = symbol;
286 unsigned char *from, *to;
287 static int virgin = 1;
288 static short litcnt[
MAXBITS+1], litsym[256];
289 static short lencnt[
MAXBITS+1], lensym[16];
290 static short distcnt[
MAXBITS+1], distsym[64];
291 static struct huffman litcode = {litcnt, litsym};
292 static struct huffman lencode = {lencnt, lensym};
293 static struct huffman distcode = {distcnt, distsym};
295 static const unsigned char litlen[] = {
296 11, 124, 8, 7, 28, 7, 188, 13, 76, 4, 10, 8, 12, 10, 12, 10, 8, 23, 8,
297 9, 7, 6, 7, 8, 7, 6, 55, 8, 23, 24, 12, 11, 7, 9, 11, 12, 6, 7, 22, 5,
298 7, 24, 6, 11, 9, 6, 7, 22, 7, 11, 38, 7, 9, 8, 25, 11, 8, 11, 9, 12,
299 8, 12, 5, 38, 5, 38, 5, 11, 7, 5, 6, 21, 6, 10, 53, 8, 7, 24, 10, 27,
300 44, 253, 253, 253, 252, 252, 252, 13, 12, 45, 12, 45, 12, 61, 12, 45,
303 static const unsigned char lenlen[] = {2, 35, 36, 53, 38, 23};
305 static const unsigned char distlen[] = {2, 20, 53, 230, 247, 151, 248};
306 static const short base[16] = {
307 3, 2, 4, 5, 6, 7, 8, 9, 10, 12, 16, 24, 40, 72, 136, 264};
308 static const char extra[16] = {
309 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8};
313 construct(&litcode, litlen,
sizeof(litlen));
314 construct(&lencode, lenlen,
sizeof(lenlen));
315 construct(&distcode, distlen,
sizeof(distlen));
321 if (lit > 1)
return -1;
323 if (dict < 4 || dict > 6)
return -2;
329 symbol =
decode(s, &lencode);
330 len = base[symbol] +
bits(s, extra[symbol]);
331 if (len == 519)
break;
334 symbol = len == 2 ? 2 : dict;
335 dist =
decode(s, &distcode) << symbol;
336 dist +=
bits(s, symbol);
338 if (s->first && dist > s->next)
343 to = s->out + s->next;
346 if (s->next < dist) {
351 if (copy > len) copy =
len;
358 if (s->outfun(s->outhow, s->out, s->next))
return 1;
366 symbol = lit ?
decode(s, &litcode) :
bits(s, 8);
367 s->out[s->next++] = symbol;
369 if (s->outfun(s->outhow, s->out, s->next))
return 1;
398 if (setjmp(s.env) != 0)
404 if (err != 1 && s.next && s.outfun(s.outhow, s.out, s.next) && err == 0)
418 static unsigned char hold[
CHUNK];
421 return fread(hold, 1,
CHUNK, (FILE *)how);
424 local int outf(
void *how,
unsigned char *
buf,
unsigned len)
426 return fwrite(
buf, 1, len, (FILE *)how) !=
len;
435 ret =
blast(
inf, stdin, outf, stdout);
436 if (ret != 0) fprintf(stderr,
"blast error: %d\n", ret);
440 while (getchar() !=
EOF) n++;
441 if (n) fprintf(stderr,
"blast warning: %d unused bytes of input\n", n);
GLenum GLuint GLenum GLsizei length
for(n=1;n< outline->n_points;n++)
int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow)
local int construct(struct huffman *h, const unsigned char *rep, int n)
GLfloat GLfloat GLfloat GLfloat h
unsigned(* blast_in)(void *how, unsigned char **buf)
local int bits(struct state *s, int need)
GLenum GLuint GLenum GLsizei const GLchar * buf
local int decomp(struct state *s)
local int out(void *out_desc, unsigned char *buf, unsigned len)
int inf(FILE *source, FILE *dest)
local int decode(struct state *s, struct huffman *h)
GLuint GLuint GLsizei count
int(* blast_out)(void *how, unsigned char *buf, unsigned len)