Lines Matching refs:state

5 local void fixedtables OF((struct inflate_state FAR *state));
10 struct inflate_state FAR *state;
12 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
13 state = (struct inflate_state FAR *)strm->state;
14 strm->total_in = strm->total_out = state->total = 0;
17 state->mode = HEAD;
18 state->last = 0;
19 state->havedict = 0;
20 state->dmax = 32768U;
21 state->head = Z_NULL;
22 state->wsize = 0;
23 state->whave = 0;
24 state->wnext = 0;
25 state->hold = 0;
26 state->bits = 0;
27 state->lencode = state->distcode = state->next = state->codes;
36 struct inflate_state FAR *state;
45 state = (struct inflate_state FAR *)
47 if (state == Z_NULL) return Z_MEM_ERROR;
49 strm->state = (struct internal_state FAR *)state;
51 state->wrap = 0;
55 state->wrap = (windowBits >> 4) + 1;
61 ZFREE(strm, state);
62 strm->state = Z_NULL;
65 state->wbits = (unsigned)windowBits;
66 state->window = Z_NULL;
75 local void fixedtables(struct inflate_state FAR *state)
77 state->lencode = lenfix;
78 state->lenbits = 9;
79 state->distcode = distfix;
80 state->distbits = 5;
99 struct inflate_state FAR *state;
102 state = (struct inflate_state FAR *)strm->state;
105 if (state->window == Z_NULL) {
106 state->window = (unsigned char FAR *)
107 ZALLOC(strm, 1U << state->wbits,
109 if (state->window == Z_NULL) return 1;
113 if (state->wsize == 0) {
114 state->wsize = 1U << state->wbits;
115 state->wnext = 0;
116 state->whave = 0;
119 /* copy state->wsize or less output bytes into the circular window */
121 if (copy >= state->wsize) {
122 zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
123 state->wnext = 0;
124 state->whave = state->wsize;
127 dist = state->wsize - state->wnext;
129 zmemcpy(state->window + state->wnext, strm->next_out - copy, dist);
132 zmemcpy(state->window, strm->next_out - copy, copy);
133 state->wnext = copy;
134 state->whave = state->wsize;
137 state->wnext += dist;
138 if (state->wnext == state->wsize) state->wnext = 0;
139 if (state->whave < state->wsize) state->whave += dist;
150 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
174 /* Load registers with state in inflate() for speed */
181 hold = state->hold; \
182 bits = state->bits; \
185 /* Restore state from registers in inflate() */
192 state->hold = hold; \
193 state->bits = bits; \
245 inflate() uses a state machine to process as much input data and generate as
246 much output data as possible before returning. The state machine is
249 for (;;) switch (state) {
255 state = STATEm;
262 next state. The NEEDBITS() macro is usually the way the state evaluates
285 state information is maintained to continue the loop where it left off
287 would all have to actually be part of the saved state in case NEEDBITS()
296 state = STATEx;
299 As shown above, if the next state is also the next case, then the break
302 A state may also return if there is not enough output space available to
303 complete that state. Those states are copying stored data, writing a
327 struct inflate_state FAR *state;
346 if (strm == Z_NULL || strm->state == Z_NULL ||
350 state = (struct inflate_state FAR *)strm->state;
351 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
357 switch (state->mode) {
359 if (state->wrap == 0) {
360 state->mode = TYPEDO;
365 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
366 state->check = crc32(0L, Z_NULL, 0);
367 CRC2(state->check, hold);
369 state->mode = FLAGS;
372 state->flags = 0; /* expect zlib header */
373 if (state->head != Z_NULL)
374 state->head->done = -1;
375 if (!(state->wrap & 1) || /* check if zlib header allowed */
381 state->mode = BAD;
386 state->mode = BAD;
391 if (len > state->wbits) {
393 state->mode = BAD;
396 state->dmax = 1U << len;
398 strm->adler = state->check = adler32(0L, Z_NULL, 0);
399 state->mode = hold & 0x200 ? DICTID : TYPE;
405 state->flags = (int)(hold);
406 if ((state->flags & 0xff) != Z_DEFLATED) {
408 state->mode = BAD;
411 if (state->flags & 0xe000) {
413 state->mode = BAD;
416 if (state->head != Z_NULL)
417 state->head->text = (int)((hold >> 8) & 1);
418 if (state->flags & 0x0200) CRC2(state->check, hold);
420 state->mode = TIME;
423 if (state->head != Z_NULL)
424 state->head->time = hold;
425 if (state->flags & 0x0200) CRC4(state->check, hold);
427 state->mode = OS;
430 if (state->head != Z_NULL) {
431 state->head->xflags = (int)(hold & 0xff);
432 state->head->os = (int)(hold >> 8);
434 if (state->flags & 0x0200) CRC2(state->check, hold);
436 state->mode = EXLEN;
438 if (state->flags & 0x0400) {
440 state->length = (unsigned)(hold);
441 if (state->head != Z_NULL)
442 state->head->extra_len = (unsigned)hold;
443 if (state->flags & 0x0200) CRC2(state->check, hold);
446 else if (state->head != Z_NULL)
447 state->head->extra = Z_NULL;
448 state->mode = EXTRA;
450 if (state->flags & 0x0400) {
451 copy = state->length;
454 if (state->head != Z_NULL &&
455 state->head->extra != Z_NULL &&
456 (len = state->head->extra_len - state->length) <
457 state->head->extra_max) {
458 zmemcpy(state->head->extra + len, next,
459 len + copy > state->head->extra_max ?
460 state->head->extra_max - len : copy);
462 if (state->flags & 0x0200)
463 state->check = crc32(state->check, next, copy);
466 state->length -= copy;
468 if (state->length) goto inf_leave;
470 state->length = 0;
471 state->mode = NAME;
473 if (state->flags & 0x0800) {
478 if (state->head != Z_NULL &&
479 state->head->name != Z_NULL &&
480 state->length < state->head->name_max)
481 state->head->name[state->length++] = len;
483 if (state->flags & 0x0200)
484 state->check = crc32(state->check, next, copy);
489 else if (state->head != Z_NULL)
490 state->head->name = Z_NULL;
491 state->length = 0;
492 state->mode = COMMENT;
494 if (state->flags & 0x1000) {
499 if (state->head != Z_NULL &&
500 state->head->comment != Z_NULL &&
501 state->length < state->head->comm_max)
502 state->head->comment[state->length++] = len;
504 if (state->flags & 0x0200)
505 state->check = crc32(state->check, next, copy);
510 else if (state->head != Z_NULL)
511 state->head->comment = Z_NULL;
512 state->mode = HCRC;
514 if (state->flags & 0x0200) {
516 if (hold != (state->check & 0xffff)) {
518 state->mode = BAD;
523 if (state->head != Z_NULL) {
524 state->head->hcrc = (int)((state->flags >> 9) & 1);
525 state->head->done = 1;
527 strm->adler = state->check = crc32(0L, Z_NULL, 0);
528 state->mode = TYPE;
533 strm->adler = state->check = REVERSE(hold);
535 state->mode = DICT;
537 if (state->havedict == 0) {
541 strm->adler = state->check = adler32(0L, Z_NULL, 0);
542 state->mode = TYPE;
547 if (state->last) {
549 state->mode = CHECK;
553 state->last = BITS(1);
558 state->last ? " (last)" : ""));
559 state->mode = STORED;
562 fixedtables(state);
564 state->last ? " (last)" : ""));
565 state->mode = LEN; /* decode codes */
569 state->last ? " (last)" : ""));
570 state->mode = TABLE;
574 state->mode = BAD;
583 state->mode = BAD;
586 state->length = (unsigned)hold & 0xffff;
588 state->length));
590 state->mode = COPY;
592 copy = state->length;
602 state->length -= copy;
606 state->mode = TYPE;
610 state->nlen = BITS(5) + 257;
612 state->ndist = BITS(5) + 1;
614 state->ncode = BITS(4) + 4;
617 if (state->nlen > 286 || state->ndist > 30) {
619 state->mode = BAD;
624 state->have = 0;
625 state->mode = LENLENS;
627 while (state->have < state->ncode) {
629 state->lens[order[state->have++]] = (unsigned short)BITS(3);
632 while (state->have < 19)
633 state->lens[order[state->have++]] = 0;
634 state->next = state->codes;
635 state->lencode = (code const FAR *)(state->next);
636 state->lenbits = 7;
637 ret = inflate_table(CODES, state->lens, 19, &(state->next),
638 &(state->lenbits), state->work);
641 state->mode = BAD;
645 state->have = 0;
646 state->mode = CODELENS;
648 while (state->have < state->nlen + state->ndist) {
650 this = state->lencode[BITS(state->lenbits)];
657 state->lens[state->have++] = this.val;
663 if (state->have == 0) {
665 state->mode = BAD;
668 len = state->lens[state->have - 1];
686 if (state->have + copy > state->nlen + state->ndist) {
688 state->mode = BAD;
692 state->lens[state->have++] = (unsigned short)len;
697 if (state->mode == BAD) break;
700 state->next = state->codes;
701 state->lencode = (code const FAR *)(state->next);
702 state->lenbits = 9;
703 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
704 &(state->lenbits), state->work);
707 state->mode = BAD;
710 state->distcode = (code const FAR *)(state->next);
711 state->distbits = 6;
712 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
713 &(state->next), &(state->distbits), state->work);
716 state->mode = BAD;
720 state->mode = LEN;
730 this = state->lencode[BITS(state->lenbits)];
737 this = state->lencode[last.val +
745 state->length = (unsigned)this.val;
750 state->mode = LIT;
755 state->mode = TYPE;
760 state->mode = BAD;
763 state->extra = (unsigned)(this.op) & 15;
764 state->mode = LENEXT;
766 if (state->extra) {
767 NEEDBITS(state->extra);
768 state->length += BITS(state->extra);
769 DROPBITS(state->extra);
771 Tracevv((stderr, "inflate: length %u\n", state->length));
772 state->mode = DIST;
775 this = state->distcode[BITS(state->distbits)];
782 this = state->distcode[last.val +
792 state->mode = BAD;
795 state->offset = (unsigned)this.val;
796 state->extra = (unsigned)(this.op) & 15;
797 state->mode = DISTEXT;
799 if (state->extra) {
800 NEEDBITS(state->extra);
801 state->offset += BITS(state->extra);
802 DROPBITS(state->extra);
805 if (state->offset > state->dmax) {
807 state->mode = BAD;
811 if (state->offset > state->whave + out - left) {
813 state->mode = BAD;
816 Tracevv((stderr, "inflate: distance %u\n", state->offset));
817 state->mode = MATCH;
821 if (state->offset > copy) { /* copy from window */
822 copy = state->offset - copy;
823 if (copy > state->wnext) {
824 copy -= state->wnext;
825 from = state->window + (state->wsize - copy);
828 from = state->window + (state->wnext - copy);
829 if (copy > state->length) copy = state->length;
832 from = put - state->offset;
833 copy = state->length;
837 state->length -= copy;
841 if (state->length == 0) state->mode = LEN;
845 *put++ = (unsigned char)(state->length);
847 state->mode = LEN;
850 if (state->wrap) {
854 state->total += out;
856 strm->adler = state->check =
857 UPDATE(state->check, put - out, out);
861 state->flags ? hold :
863 REVERSE(hold)) != state->check) {
865 state->mode = BAD;
872 state->mode = LENGTH;
874 if (state->wrap && state->flags) {
876 if (hold != (state->total & 0xffffffffUL)) {
878 state->mode = BAD;
885 state->mode = DONE;
902 error. Call updatewindow() to create and/or update the window state.
907 if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
909 state->mode = MEM;
916 state->total += out;
917 if (state->wrap && out)
918 strm->adler = state->check =
919 UPDATE(state->check, strm->next_out - out, out);
920 strm->data_type = state->bits + (state->last ? 64 : 0) +
921 (state->mode == TYPE ? 128 : 0);
929 struct inflate_state FAR *state;
930 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
932 state = (struct inflate_state FAR *)strm->state;
933 if (state->window != Z_NULL) {
935 ZFREE(strm, state->window);
937 ZFREE(strm, strm->state);
938 strm->state = Z_NULL;