Lines Matching full:state

25     struct inflate_state *state;  in zlib_inflateReset()  local
27 if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR; in zlib_inflateReset()
28 state = (struct inflate_state *)strm->state; in zlib_inflateReset()
29 strm->total_in = strm->total_out = state->total = 0; in zlib_inflateReset()
32 state->mode = HEAD; in zlib_inflateReset()
33 state->last = 0; in zlib_inflateReset()
34 state->havedict = 0; in zlib_inflateReset()
35 state->dmax = 32768U; in zlib_inflateReset()
36 state->hold = 0; in zlib_inflateReset()
37 state->bits = 0; in zlib_inflateReset()
38 state->lencode = state->distcode = state->next = state->codes; in zlib_inflateReset()
41 state->wsize = 1U << state->wbits; in zlib_inflateReset()
42 state->write = 0; in zlib_inflateReset()
43 state->whave = 0; in zlib_inflateReset()
50 struct inflate_state *state; in zlib_inflateInit2() local
55 state = &WS(strm)->inflate_state; in zlib_inflateInit2()
56 strm->state = (struct internal_state *)state; in zlib_inflateInit2()
59 state->wrap = 0; in zlib_inflateInit2()
63 state->wrap = (windowBits >> 4) + 1; in zlib_inflateInit2()
68 state->wbits = (unsigned)windowBits; in zlib_inflateInit2()
69 state->window = &WS(strm)->working_window[0]; in zlib_inflateInit2()
75 Return state with length and distance decoding tables and index sizes set to
78 static void zlib_fixedtables(struct inflate_state *state) in zlib_fixedtables() argument
81 state->lencode = lenfix; in zlib_fixedtables()
82 state->lenbits = 9; in zlib_fixedtables()
83 state->distcode = distfix; in zlib_fixedtables()
84 state->distbits = 5; in zlib_fixedtables()
103 struct inflate_state *state; in zlib_updatewindow() local
106 state = (struct inflate_state *)strm->state; in zlib_updatewindow()
108 /* copy state->wsize or less output bytes into the circular window */ in zlib_updatewindow()
110 if (copy >= state->wsize) { in zlib_updatewindow()
111 memcpy(state->window, strm->next_out - state->wsize, state->wsize); in zlib_updatewindow()
112 state->write = 0; in zlib_updatewindow()
113 state->whave = state->wsize; in zlib_updatewindow()
116 dist = state->wsize - state->write; in zlib_updatewindow()
118 memcpy(state->window + state->write, strm->next_out - copy, dist); in zlib_updatewindow()
121 memcpy(state->window, strm->next_out - copy, copy); in zlib_updatewindow()
122 state->write = copy; in zlib_updatewindow()
123 state->whave = state->wsize; in zlib_updatewindow()
126 state->write += dist; in zlib_updatewindow()
127 if (state->write == state->wsize) state->write = 0; in zlib_updatewindow()
128 if (state->whave < state->wsize) state->whave += dist; in zlib_updatewindow()
148 struct inflate_state *state; in zlib_inflateSyncPacket() local
150 if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR; in zlib_inflateSyncPacket()
151 state = (struct inflate_state *)strm->state; in zlib_inflateSyncPacket()
153 if (state->mode == STORED && state->bits == 0) { in zlib_inflateSyncPacket()
154 state->mode = TYPE; in zlib_inflateSyncPacket()
165 /* Load registers with state in inflate() for speed */
172 hold = state->hold; \
173 bits = state->bits; \
176 /* Restore state from registers in inflate() */
183 state->hold = hold; \
184 state->bits = bits; \
236 inflate() uses a state machine to process as much input data and generate as
237 much output data as possible before returning. The state machine is
240 for (;;) switch (state) {
246 state = STATEm;
253 next state. The NEEDBITS() macro is usually the way the state evaluates
276 state information is maintained to continue the loop where it left off
278 would all have to actually be part of the saved state in case NEEDBITS()
287 state = STATEx;
290 As shown above, if the next state is also the next case, then the break
293 A state may also return if there is not enough output space available to
294 complete that state. Those states are copying stored data, writing a
319 struct inflate_state *state; in zlib_inflate() local
338 if (strm == NULL || strm->state == NULL || in zlib_inflate()
342 state = (struct inflate_state *)strm->state; in zlib_inflate()
344 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */ in zlib_inflate()
350 switch (state->mode) { in zlib_inflate()
352 if (state->wrap == 0) { in zlib_inflate()
353 state->mode = TYPEDO; in zlib_inflate()
360 state->mode = BAD; in zlib_inflate()
365 state->mode = BAD; in zlib_inflate()
370 if (len > state->wbits) { in zlib_inflate()
372 state->mode = BAD; in zlib_inflate()
375 state->dmax = 1U << len; in zlib_inflate()
376 strm->adler = state->check = zlib_adler32(0L, NULL, 0); in zlib_inflate()
377 state->mode = hold & 0x200 ? DICTID : TYPE; in zlib_inflate()
382 strm->adler = state->check = REVERSE(hold); in zlib_inflate()
384 state->mode = DICT; in zlib_inflate()
387 if (state->havedict == 0) { in zlib_inflate()
391 strm->adler = state->check = zlib_adler32(0L, NULL, 0); in zlib_inflate()
392 state->mode = TYPE; in zlib_inflate()
398 if (state->last) { in zlib_inflate()
400 state->mode = CHECK; in zlib_inflate()
404 state->last = BITS(1); in zlib_inflate()
408 state->mode = STORED; in zlib_inflate()
411 zlib_fixedtables(state); in zlib_inflate()
412 state->mode = LEN; /* decode codes */ in zlib_inflate()
415 state->mode = TABLE; in zlib_inflate()
419 state->mode = BAD; in zlib_inflate()
428 state->mode = BAD; in zlib_inflate()
431 state->length = (unsigned)hold & 0xffff; in zlib_inflate()
433 state->mode = COPY; in zlib_inflate()
436 copy = state->length; in zlib_inflate()
446 state->length -= copy; in zlib_inflate()
449 state->mode = TYPE; in zlib_inflate()
453 state->nlen = BITS(5) + 257; in zlib_inflate()
455 state->ndist = BITS(5) + 1; in zlib_inflate()
457 state->ncode = BITS(4) + 4; in zlib_inflate()
460 if (state->nlen > 286 || state->ndist > 30) { in zlib_inflate()
462 state->mode = BAD; in zlib_inflate()
466 state->have = 0; in zlib_inflate()
467 state->mode = LENLENS; in zlib_inflate()
470 while (state->have < state->ncode) { in zlib_inflate()
472 state->lens[order[state->have++]] = (unsigned short)BITS(3); in zlib_inflate()
475 while (state->have < 19) in zlib_inflate()
476 state->lens[order[state->have++]] = 0; in zlib_inflate()
477 state->next = state->codes; in zlib_inflate()
478 state->lencode = (code const *)(state->next); in zlib_inflate()
479 state->lenbits = 7; in zlib_inflate()
480 ret = zlib_inflate_table(CODES, state->lens, 19, &(state->next), in zlib_inflate()
481 &(state->lenbits), state->work); in zlib_inflate()
484 state->mode = BAD; in zlib_inflate()
487 state->have = 0; in zlib_inflate()
488 state->mode = CODELENS; in zlib_inflate()
491 while (state->have < state->nlen + state->ndist) { in zlib_inflate()
493 this = state->lencode[BITS(state->lenbits)]; in zlib_inflate()
500 state->lens[state->have++] = this.val; in zlib_inflate()
506 if (state->have == 0) { in zlib_inflate()
508 state->mode = BAD; in zlib_inflate()
511 len = state->lens[state->have - 1]; in zlib_inflate()
529 if (state->have + copy > state->nlen + state->ndist) { in zlib_inflate()
531 state->mode = BAD; in zlib_inflate()
535 state->lens[state->have++] = (unsigned short)len; in zlib_inflate()
540 if (state->mode == BAD) break; in zlib_inflate()
543 state->next = state->codes; in zlib_inflate()
544 state->lencode = (code const *)(state->next); in zlib_inflate()
545 state->lenbits = 9; in zlib_inflate()
546 ret = zlib_inflate_table(LENS, state->lens, state->nlen, &(state->next), in zlib_inflate()
547 &(state->lenbits), state->work); in zlib_inflate()
550 state->mode = BAD; in zlib_inflate()
553 state->distcode = (code const *)(state->next); in zlib_inflate()
554 state->distbits = 6; in zlib_inflate()
555 ret = zlib_inflate_table(DISTS, state->lens + state->nlen, state->ndist, in zlib_inflate()
556 &(state->next), &(state->distbits), state->work); in zlib_inflate()
559 state->mode = BAD; in zlib_inflate()
562 state->mode = LEN; in zlib_inflate()
572 this = state->lencode[BITS(state->lenbits)]; in zlib_inflate()
579 this = state->lencode[last.val + in zlib_inflate()
587 state->length = (unsigned)this.val; in zlib_inflate()
589 state->mode = LIT; in zlib_inflate()
593 state->mode = TYPE; in zlib_inflate()
598 state->mode = BAD; in zlib_inflate()
601 state->extra = (unsigned)(this.op) & 15; in zlib_inflate()
602 state->mode = LENEXT; in zlib_inflate()
605 if (state->extra) { in zlib_inflate()
606 NEEDBITS(state->extra); in zlib_inflate()
607 state->length += BITS(state->extra); in zlib_inflate()
608 DROPBITS(state->extra); in zlib_inflate()
610 state->mode = DIST; in zlib_inflate()
614 this = state->distcode[BITS(state->distbits)]; in zlib_inflate()
621 this = state->distcode[last.val + in zlib_inflate()
631 state->mode = BAD; in zlib_inflate()
634 state->offset = (unsigned)this.val; in zlib_inflate()
635 state->extra = (unsigned)(this.op) & 15; in zlib_inflate()
636 state->mode = DISTEXT; in zlib_inflate()
639 if (state->extra) { in zlib_inflate()
640 NEEDBITS(state->extra); in zlib_inflate()
641 state->offset += BITS(state->extra); in zlib_inflate()
642 DROPBITS(state->extra); in zlib_inflate()
645 if (state->offset > state->dmax) { in zlib_inflate()
647 state->mode = BAD; in zlib_inflate()
651 if (state->offset > state->whave + out - left) { in zlib_inflate()
653 state->mode = BAD; in zlib_inflate()
656 state->mode = MATCH; in zlib_inflate()
661 if (state->offset > copy) { /* copy from window */ in zlib_inflate()
662 copy = state->offset - copy; in zlib_inflate()
663 if (copy > state->write) { in zlib_inflate()
664 copy -= state->write; in zlib_inflate()
665 from = state->window + (state->wsize - copy); in zlib_inflate()
668 from = state->window + (state->write - copy); in zlib_inflate()
669 if (copy > state->length) copy = state->length; in zlib_inflate()
672 from = put - state->offset; in zlib_inflate()
673 copy = state->length; in zlib_inflate()
677 state->length -= copy; in zlib_inflate()
681 if (state->length == 0) state->mode = LEN; in zlib_inflate()
685 *put++ = (unsigned char)(state->length); in zlib_inflate()
687 state->mode = LEN; in zlib_inflate()
690 if (state->wrap) { in zlib_inflate()
694 state->total += out; in zlib_inflate()
696 strm->adler = state->check = in zlib_inflate()
697 UPDATE(state->check, put - out, out); in zlib_inflate()
700 REVERSE(hold)) != state->check) { in zlib_inflate()
702 state->mode = BAD; in zlib_inflate()
707 state->mode = DONE; in zlib_inflate()
725 error. Call zlib_updatewindow() to create and/or update the window state. in zlib_inflate()
729 if (state->wsize || (state->mode < CHECK && out != strm->avail_out)) in zlib_inflate()
736 state->total += out; in zlib_inflate()
737 if (state->wrap && out) in zlib_inflate()
738 strm->adler = state->check = in zlib_inflate()
739 UPDATE(state->check, strm->next_out - out, out); in zlib_inflate()
741 strm->data_type = state->bits + (state->last ? 64 : 0) + in zlib_inflate()
742 (state->mode == TYPE ? 128 : 0); in zlib_inflate()
756 if (strm == NULL || strm->state == NULL) in zlib_inflateEnd()
764 * i.e. no pending output but this should always be the case. The state must
771 struct inflate_state *state = (struct inflate_state *)z->state; in zlib_inflateIncomp() local
775 if (state->mode != TYPE && state->mode != HEAD) in zlib_inflateIncomp()
788 z->adler = state->check = in zlib_inflateIncomp()
789 UPDATE(state->check, z->next_in, z->avail_in); in zlib_inflateIncomp()
794 state->total += z->avail_in; in zlib_inflateIncomp()