Lines Matching refs:state
197 fill(State_t* state)
201 if (state->eof)
203 if ((r = sfrd(state->codex->sp, state->buf, sizeof(state->buf), &state->codex->sfdisc)) <= 0)
205 state->eof = 1;
208 state->ie = (state->ip = state->buf) + r;
209 return *state->ip++;
213 State_t* state,
226 i = NEXTBYTE(state) + 1; /* length/count pairs to read */
229 b = ((j = NEXTBYTE(state)) & 0xf) + 1; /* bits in code (1..16) */
241 static ssize_t explode_lit8(State_t* state, char *buff, size_t size)
255 tb = state->tb;
256 tl = state->tl;
257 td = state->td;
258 bb = state->bb;
259 bl = state->bl;
260 bd = state->bd;
263 s = state->s;
264 w = state->w;
265 u = state->u;
270 NEEDBITS(state, 1);
271 if(state->bit_buf & 1) /* then literal--decode it */
273 DUMPBITS(state, 1);
275 NEEDBITS(state, (ulg)bb); /* get coded literal */
276 t = tb + IGETBITS(state, bb);
282 DUMPBITS(state, t->b);
284 NEEDBITS(state, e);
285 t = t->v.t + IGETBITS(state, e);
288 DUMPBITS(state, t->b);
289 buff[j++] = state->slide[w++] = (uch)t->v.n;
294 state->u = u;
295 state->w = w;
296 state->s = s;
302 DUMPBITS(state, 1);
303 NEEDBITS(state, 7); /* get distance low bits */
304 d = GETBITS(state, 7);
305 DUMPBITS(state, 7);
306 NEEDBITS(state, (ulg)bd); /* get coded distance high bits */
307 t = td + IGETBITS(state, bd);
313 DUMPBITS(state, t->b);
315 NEEDBITS(state, e);
316 t = t->v.t + IGETBITS(state, e);
319 DUMPBITS(state, t->b);
321 NEEDBITS(state, (ulg)bl); /* get coded length */
322 t = tl + IGETBITS(state, bl);
328 DUMPBITS(state, t->b);
330 NEEDBITS(state, e);
331 t = t->v.t + IGETBITS(state, e);
334 DUMPBITS(state, t->b);
338 NEEDBITS(state, 8);
339 n += GETBITS(state, 8);
340 DUMPBITS(state, 8);
357 buff[j++] = state->slide[w++] = state->slide[d++];
363 state->u = u;
364 state->n = n;
365 state->d = d;
366 state->w = w;
367 state->s = s;
370 state->n = 0;
374 state->n = 0;
375 state->w = 0;
376 state->eof = 1;
382 static ssize_t explode_lit4(State_t* state, char *buff, size_t size)
396 tb = state->tb;
397 tl = state->tl;
398 td = state->td;
399 bb = state->bb;
400 bl = state->bl;
401 bd = state->bd;
404 s = state->s;
405 w = state->w;
406 u = state->u;
411 NEEDBITS(state, 1);
412 if(state->bit_buf & 1) /* then literal--decode it */
414 DUMPBITS(state, 1);
416 NEEDBITS(state, (ulg)bb); /* get coded literal */
417 t = tb + IGETBITS(state, bb);
423 DUMPBITS(state, t->b);
425 NEEDBITS(state, e);
426 t = t->v.t + IGETBITS(state, e);
428 DUMPBITS(state, t->b);
429 buff[j++] = state->slide[w++] = (uch)t->v.n;
434 state->u = u;
435 state->w = w;
436 state->s = s;
442 DUMPBITS(state, 1);
443 NEEDBITS(state, 6); /* get distance low bits */
444 d = GETBITS(state, 6);
445 DUMPBITS(state, 6);
446 NEEDBITS(state, (ulg)bd); /* get coded distance high bits */
447 t = td + IGETBITS(state, bd);
453 DUMPBITS(state, t->b);
455 NEEDBITS(state, e);
456 t = t->v.t + IGETBITS(state, e);
459 DUMPBITS(state, t->b);
461 NEEDBITS(state, (ulg)bl); /* get coded length */
462 t = tl + IGETBITS(state, bl);
468 DUMPBITS(state, t->b);
470 NEEDBITS(state, e);
471 t = t->v.t + IGETBITS(state, e);
474 DUMPBITS(state, t->b);
478 NEEDBITS(state, 8);
479 n += GETBITS(state, 8);
480 DUMPBITS(state, 8);
497 buff[j++] = state->slide[w++] = state->slide[d++];
503 state->u = u;
504 state->n = n;
505 state->d = d;
506 state->w = w;
507 state->s = s;
510 state->n = 0;
514 state->n = 0;
515 state->w = 0;
516 state->eof = 1;
522 static ssize_t explode_nolit8(State_t* state, char *buff, size_t size)
533 Huff_t *tl, *td; /* length and distance state tables */
536 tl = state->tl;
537 td = state->td;
538 bl = state->bl;
539 bd = state->bd;
543 s = state->s;
544 w = state->w;
545 u = state->u;
550 NEEDBITS(state, 1);
551 if(state->bit_buf & 1) /* then literal--get eight bits */
553 DUMPBITS(state, 1);
555 NEEDBITS(state, 8);
556 buff[j++] = state->slide[w++] = (uch)state->bit_buf;;
557 DUMPBITS(state, 8);
562 state->u = u;
563 state->w = w;
564 state->s = s;
570 DUMPBITS(state, 1);
571 NEEDBITS(state, 7); /* get distance low bits */
572 d = GETBITS(state, 7);
573 DUMPBITS(state, 7);
574 NEEDBITS(state, (ulg)bd); /* get coded distance high bits */
575 t = td + IGETBITS(state, bd);
581 DUMPBITS(state, t->b);
583 NEEDBITS(state, e);
584 t = t->v.t + IGETBITS(state, e);
587 DUMPBITS(state, t->b);
589 NEEDBITS(state, (ulg)bl); /* get coded length */
590 t = tl + IGETBITS(state, bl);
596 DUMPBITS(state, t->b);
598 NEEDBITS(state, e);
599 t = t->v.t + IGETBITS(state, e);
602 DUMPBITS(state, t->b);
606 NEEDBITS(state, 8);
607 n += GETBITS(state, 8);
608 DUMPBITS(state, 8);
625 buff[j++] = state->slide[w++] = state->slide[d++];
631 state->u = u;
632 state->n = n;
633 state->d = d;
634 state->w = w;
635 state->s = s;
638 state->n = 0;
642 state->n = 0;
643 state->w = 0;
644 state->eof = 1;
650 static ssize_t explode_nolit4(State_t* state, char *buff, size_t size)
661 Huff_t *tl, *td; /* length and distance state tables */
664 tl = state->tl;
665 td = state->td;
666 bl = state->bl;
667 bd = state->bd;
670 s = state->s;
671 w = state->w;
672 u = state->u;
677 NEEDBITS(state, 1);
678 if(state->bit_buf & 1) /* then literal--get eight bits */
680 DUMPBITS(state, 1);
682 NEEDBITS(state, 8);
683 buff[j++] = state->slide[w++] = (uch)state->bit_buf;
684 DUMPBITS(state, 8);
689 state->u = u;
690 state->w = w;
691 state->s = s;
697 DUMPBITS(state, 1);
698 NEEDBITS(state, 6); /* get distance low bits */
699 d = GETBITS(state, 6);
700 DUMPBITS(state, 6);
701 NEEDBITS(state, (ulg)bd); /* get coded distance high bits */
702 t = td + IGETBITS(state, bd);
708 DUMPBITS(state, t->b);
710 NEEDBITS(state, e);
711 t = t->v.t + IGETBITS(state, e);
714 DUMPBITS(state, t->b);
716 NEEDBITS(state, (ulg)bl); /* get coded length */
717 t = tl + IGETBITS(state, bl);
723 DUMPBITS(state, t->b);
725 NEEDBITS(state, e);
726 t = t->v.t + IGETBITS(state, e);
729 DUMPBITS(state, t->b);
733 NEEDBITS(state, 8);
734 n += GETBITS(state, 8);
735 DUMPBITS(state, 8);
752 buff[j++] = state->slide[w++] = state->slide[d++];
758 state->u = u;
759 state->n = n;
760 state->d = d;
761 state->w = w;
762 state->s = s;
765 state->n = 0;
769 state->n = 0;
770 state->w = 0;
771 state->eof = 1;
778 State_t* state;
784 if (!(state = newof(0, State_t, 1, 0)))
793 state->method |= EXPLODE_LIT;
796 state->method |= EXPLODE_BIG;
799 switch (state->method)
802 state->explodef = explode_nolit4;
805 state->explodef = explode_nolit8;
808 state->explodef = explode_lit4;
811 state->explodef = explode_lit8;
814 state->codex = p;
815 p->data = state;
822 State_t* state = (State_t*)p->data;
824 if (!state)
826 if (state->vm)
827 vmclose(state->vm);
828 free(state);
835 register State_t* state = (State_t*)p->data;
837 vmclear(state->vm);
838 state->ip = state->ie = 0;
839 state->eof = 0;
840 state->u = 1;
841 state->s = p->size;
848 state->bl = 7;
849 state->bd = (state->s > 200000L ? 8 : 7);
852 if(state->method & EXPLODE_LIT)
854 state->bb = 9; /* base table size for literals */
855 if(get_tree(state, state->l, 256) != 0)
858 if(huff(state->l, 256, 256, NULL, NULL,
859 &state->tb, &state->bb, state->vm) != 0)
862 if(get_tree(state, state->l, 64) != 0)
865 if(huff(state->l, 64, 0, cplen3, extra,
866 &state->tl, &state->bl, state->vm) != 0)
869 if(get_tree(state, state->l, 64) != 0)
872 if(state->method & EXPLODE_BIG)
874 if(huff(state->l, 64, 0, cpdist8, extra,
875 &state->td, &state->bd, state->vm) != 0)
880 if(huff(state->l, 64, 0, cpdist4, extra,
881 &state->td, &state->bd, state->vm) != 0)
887 if(get_tree(state, state->l, 64) != 0)
890 if(huff(state->l, 64, 0, cplen2, extra,
891 &state->tl, &state->bl, state->vm) != 0)
894 if(get_tree(state, state->l, 64) != 0)
897 if(state->method & EXPLODE_BIG)
899 if(huff(state->l, 64, 0, cpdist8, extra,
900 &state->td, &state->bd, state->vm) != 0)
905 if(huff(state->l, 64, 0, cpdist4, extra,
906 &state->td, &state->bd, state->vm) != 0)
925 register State_t* state = (State_t*)CODEX(disc)->data;
934 if(state->n > 0) /* do the copy */
938 u = state->u;
939 n = state->n;
940 d = state->d;
941 w = state->w;
954 ((char*)buff)[j++] = state->slide[w++] = state->slide[d++];
959 state->u = u;
960 state->n = n;
961 state->d = d;
962 state->w = w;
967 /* state->n == 0 */
968 if(state->eof)
971 i = (*state->explodef)(state, (char*)buff + j, size - j);