Lines Matching refs:state

35     struct inflate_state *state;
37 if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR;
38 state = (struct inflate_state *)strm->state;
39 strm->total_in = strm->total_out = state->total = 0;
42 state->mode = HEAD;
43 state->last = 0;
44 state->havedict = 0;
45 state->dmax = 32768U;
46 state->hold = 0;
47 state->bits = 0;
48 state->lencode = state->distcode = state->next = state->codes;
51 state->wsize = 1U << state->wbits;
52 state->write = 0;
53 state->whave = 0;
61 struct inflate_state *state;
66 state = &WS(strm)->inflate_state;
67 strm->state = (struct internal_state *)state;
70 state->wrap = 0;
74 state->wrap = (windowBits >> 4) + 1;
79 state->wbits = (unsigned)windowBits;
85 state->window = PTR_ALIGN(&WS(strm)->working_window[0], PAGE_SIZE);
87 state->window = &WS(strm)->working_window[0];
94 Return state with length and distance decoding tables and index sizes set to
97 static void zlib_fixedtables(struct inflate_state *state)
100 state->lencode = lenfix;
101 state->lenbits = 9;
102 state->distcode = distfix;
103 state->distbits = 5;
122 struct inflate_state *state;
125 state = (struct inflate_state *)strm->state;
127 /* copy state->wsize or less output bytes into the circular window */
129 if (copy >= state->wsize) {
130 memcpy(state->window, strm->next_out - state->wsize, state->wsize);
131 state->write = 0;
132 state->whave = state->wsize;
135 dist = state->wsize - state->write;
137 memcpy(state->window + state->write, strm->next_out - copy, dist);
140 memcpy(state->window, strm->next_out - copy, copy);
141 state->write = copy;
142 state->whave = state->wsize;
145 state->write += dist;
146 if (state->write == state->wsize) state->write = 0;
147 if (state->whave < state->wsize) state->whave += dist;
167 struct inflate_state *state;
169 if (strm == NULL || strm->state == NULL) return Z_STREAM_ERROR;
170 state = (struct inflate_state *)strm->state;
172 if (state->mode == STORED && state->bits == 0) {
173 state->mode = TYPE;
184 /* Load registers with state in inflate() for speed */
191 hold = state->hold; \
192 bits = state->bits; \
195 /* Restore state from registers in inflate() */
202 state->hold = hold; \
203 state->bits = bits; \
250 inflate() uses a state machine to process as much input data and generate as
251 much output data as possible before returning. The state machine is
254 for (;;) switch (state) {
260 state = STATEm;
267 next state. The NEEDBITS() macro is usually the way the state evaluates
290 state information is maintained to continue the loop where it left off
292 would all have to actually be part of the saved state in case NEEDBITS()
301 state = STATEx;
304 As shown above, if the next state is also the next case, then the break
307 A state may also return if there is not enough output space available to
308 complete that state. Those states are copying stored data, writing a
333 struct inflate_state *state;
352 if (strm == NULL || strm->state == NULL ||
356 state = (struct inflate_state *)strm->state;
358 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
364 switch (state->mode) {
366 if (state->wrap == 0) {
367 state->mode = TYPEDO;
374 state->mode = BAD;
379 state->mode = BAD;
384 if (len > state->wbits) {
386 state->mode = BAD;
389 state->dmax = 1U << len;
390 strm->adler = state->check = zlib_adler32(0L, NULL, 0);
391 state->mode = hold & 0x200 ? DICTID : TYPE;
396 strm->adler = state->check = REVERSE(hold);
398 state->mode = DICT;
401 if (state->havedict == 0) {
405 strm->adler = state->check = zlib_adler32(0L, NULL, 0);
406 state->mode = TYPE;
413 if (state->last) {
415 state->mode = CHECK;
419 state->last = BITS(1);
423 state->mode = STORED;
426 zlib_fixedtables(state);
427 state->mode = LEN; /* decode codes */
430 state->mode = TABLE;
434 state->mode = BAD;
443 state->mode = BAD;
446 state->length = (unsigned)hold & 0xffff;
448 state->mode = COPY;
451 copy = state->length;
461 state->length -= copy;
464 state->mode = TYPE;
468 state->nlen = BITS(5) + 257;
470 state->ndist = BITS(5) + 1;
472 state->ncode = BITS(4) + 4;
475 if (state->nlen > 286 || state->ndist > 30) {
477 state->mode = BAD;
481 state->have = 0;
482 state->mode = LENLENS;
485 while (state->have < state->ncode) {
487 state->lens[order[state->have++]] = (unsigned short)BITS(3);
490 while (state->have < 19)
491 state->lens[order[state->have++]] = 0;
492 state->next = state->codes;
493 state->lencode = (code const *)(state->next);
494 state->lenbits = 7;
495 ret = zlib_inflate_table(CODES, state->lens, 19, &(state->next),
496 &(state->lenbits), state->work);
499 state->mode = BAD;
502 state->have = 0;
503 state->mode = CODELENS;
506 while (state->have < state->nlen + state->ndist) {
508 this = state->lencode[BITS(state->lenbits)];
515 state->lens[state->have++] = this.val;
521 if (state->have == 0) {
523 state->mode = BAD;
526 len = state->lens[state->have - 1];
544 if (state->have + copy > state->nlen + state->ndist) {
546 state->mode = BAD;
550 state->lens[state->have++] = (unsigned short)len;
555 if (state->mode == BAD) break;
558 state->next = state->codes;
559 state->lencode = (code const *)(state->next);
560 state->lenbits = 9;
561 ret = zlib_inflate_table(LENS, state->lens, state->nlen, &(state->next),
562 &(state->lenbits), state->work);
565 state->mode = BAD;
568 state->distcode = (code const *)(state->next);
569 state->distbits = 6;
570 ret = zlib_inflate_table(DISTS, state->lens + state->nlen, state->ndist,
571 &(state->next), &(state->distbits), state->work);
574 state->mode = BAD;
577 state->mode = LEN;
587 this = state->lencode[BITS(state->lenbits)];
594 this = state->lencode[last.val +
602 state->length = (unsigned)this.val;
604 state->mode = LIT;
608 state->mode = TYPE;
613 state->mode = BAD;
616 state->extra = (unsigned)(this.op) & 15;
617 state->mode = LENEXT;
620 if (state->extra) {
621 NEEDBITS(state->extra);
622 state->length += BITS(state->extra);
623 DROPBITS(state->extra);
625 state->mode = DIST;
629 this = state->distcode[BITS(state->distbits)];
636 this = state->distcode[last.val +
646 state->mode = BAD;
649 state->offset = (unsigned)this.val;
650 state->extra = (unsigned)(this.op) & 15;
651 state->mode = DISTEXT;
654 if (state->extra) {
655 NEEDBITS(state->extra);
656 state->offset += BITS(state->extra);
657 DROPBITS(state->extra);
660 if (state->offset > state->dmax) {
662 state->mode = BAD;
666 if (state->offset > state->whave + out - left) {
668 state->mode = BAD;
671 state->mode = MATCH;
676 if (state->offset > copy) { /* copy from window */
677 copy = state->offset - copy;
678 if (copy > state->write) {
679 copy -= state->write;
680 from = state->window + (state->wsize - copy);
683 from = state->window + (state->write - copy);
684 if (copy > state->length) copy = state->length;
687 from = put - state->offset;
688 copy = state->length;
692 state->length -= copy;
696 if (state->length == 0) state->mode = LEN;
700 *put++ = (unsigned char)(state->length);
702 state->mode = LEN;
705 if (state->wrap) {
709 state->total += out;
711 strm->adler = state->check =
712 UPDATE(state->check, put - out, out);
715 REVERSE(hold)) != state->check) {
717 state->mode = BAD;
722 state->mode = DONE;
740 error. Call zlib_updatewindow() to create and/or update the window state.
745 (state->wsize || (state->mode < CHECK && out != strm->avail_out)))
752 state->total += out;
753 if (INFLATE_NEED_CHECKSUM(strm) && state->wrap && out)
754 strm->adler = state->check =
755 UPDATE(state->check, strm->next_out - out, out);
757 strm->data_type = state->bits + (state->last ? 64 : 0) +
758 (state->mode == TYPE ? 128 : 0);
772 if (strm == NULL || strm->state == NULL)
780 * i.e. no pending output but this should always be the case. The state must
787 struct inflate_state *state = (struct inflate_state *)z->state;
791 if (state->mode != TYPE && state->mode != HEAD)
804 z->adler = state->check =
805 UPDATE(state->check, z->next_in, z->avail_in);
810 state->total += z->avail_in;