Lines Matching defs:state

26  * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset)
30 * - Add comments on state->bits assertion in inffast.c
95 struct inflate_state FAR *state;
99 state = (struct inflate_state FAR *)strm->state;
100 if (state == Z_NULL || state->strm != strm ||
101 state->mode < HEAD || state->mode > SYNC)
107 struct inflate_state FAR *state;
110 state = (struct inflate_state FAR *)strm->state;
111 strm->total_in = strm->total_out = state->total = 0;
113 if (state->wrap) /* to support ill-conceived Java test suite */
114 strm->adler = state->wrap & 1;
115 state->mode = HEAD;
116 state->last = 0;
117 state->havedict = 0;
118 state->flags = -1;
119 state->dmax = 32768U;
120 state->head = Z_NULL;
121 state->hold = 0;
122 state->bits = 0;
123 state->lencode = state->distcode = state->next = state->codes;
124 state->sane = 1;
125 state->back = -1;
131 struct inflate_state FAR *state;
134 state = (struct inflate_state FAR *)strm->state;
135 state->wsize = 0;
136 state->whave = 0;
137 state->wnext = 0;
143 struct inflate_state FAR *state;
145 /* get the state */
147 state = (struct inflate_state FAR *)strm->state;
167 if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
168 ZFREE(strm, state->window, 1U << state->wbits);
169 state->window = Z_NULL;
172 /* update state and reset the rest of it */
173 state->wrap = wrap;
174 state->wbits = (unsigned)windowBits;
181 struct inflate_state FAR *state;
202 state = (struct inflate_state FAR *)
204 if (state == Z_NULL) return Z_MEM_ERROR;
206 strm->state = (struct internal_state FAR *)state;
207 state->strm = strm;
208 state->window = Z_NULL;
209 state->mode = HEAD; /* to pass state test in inflateReset2() */
212 ZFREE(strm, state, sizeof(struct inflate_state));
213 strm->state = Z_NULL;
224 struct inflate_state FAR *state;
229 state = (struct inflate_state FAR *)strm->state;
231 state->hold = 0;
232 state->bits = 0;
235 if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR;
237 state->hold += (unsigned)value << state->bits;
238 state->bits += (uInt)bits;
243 Return state with length and distance decoding tables and index sizes set to
252 local void fixedtables(struct inflate_state FAR *state) {
265 while (sym < 144) state->lens[sym++] = 8;
266 while (sym < 256) state->lens[sym++] = 9;
267 while (sym < 280) state->lens[sym++] = 7;
268 while (sym < 288) state->lens[sym++] = 8;
272 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
276 while (sym < 32) state->lens[sym++] = 5;
279 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
287 state->lencode = lenfix;
288 state->lenbits = 9;
289 state->distcode = distfix;
290 state->distbits = 5;
317 struct inflate_state state;
319 fixedtables(&state);
334 printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
335 state.lencode[low].bits, state.lencode[low].val);
345 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
346 state.distcode[low].val);
369 struct inflate_state FAR *state;
372 state = (struct inflate_state FAR *)strm->state;
375 if (state->window == Z_NULL) {
376 state->window = (unsigned char FAR *)
377 ZALLOC(strm, 1U << state->wbits,
379 if (state->window == Z_NULL) return 1;
383 if (state->wsize == 0) {
384 state->wsize = 1U << state->wbits;
385 state->wnext = 0;
386 state->whave = 0;
389 /* copy state->wsize or less output bytes into the circular window */
390 if (copy >= state->wsize) {
391 zmemcpy(state->window, end - state->wsize, state->wsize);
392 state->wnext = 0;
393 state->whave = state->wsize;
396 dist = state->wsize - state->wnext;
398 zmemcpy(state->window + state->wnext, end - copy, dist);
401 zmemcpy(state->window, end - copy, copy);
402 state->wnext = copy;
403 state->whave = state->wsize;
406 state->wnext += dist;
407 if (state->wnext == state->wsize) state->wnext = 0;
408 if (state->whave < state->wsize) state->whave += dist;
419 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
443 /* Load registers with state in inflate() for speed */
450 hold = state->hold; \
451 bits = state->bits; \
454 /* Restore state from registers in inflate() */
461 state->hold = hold; \
462 state->bits = bits; \
509 inflate() uses a state machine to process as much input data and generate as
510 much output data as possible before returning. The state machine is
513 for (;;) switch (state) {
519 state = STATEm;
526 next state. The NEEDBITS() macro is usually the way the state evaluates
549 state information is maintained to continue the loop where it left off
551 would all have to actually be part of the saved state in case NEEDBITS()
560 state = STATEx;
563 As shown above, if the next state is also the next case, then the break
566 A state may also return if there is not enough output space available to
567 complete that state. Those states are copying stored data, writing a
591 struct inflate_state FAR *state;
614 state = (struct inflate_state FAR *)strm->state;
615 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
621 switch (state->mode) {
623 if (state->wrap == 0) {
624 state->mode = TYPEDO;
629 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
630 if (state->wbits == 0)
631 state->wbits = 15;
632 state->check = crc32(0L, Z_NULL, 0);
633 CRC2(state->check, hold);
635 state->mode = FLAGS;
638 if (state->head != Z_NULL)
639 state->head->done = -1;
640 if (!(state->wrap & 1) || /* check if zlib header allowed */
650 state->mode = BAD;
659 state->mode = BAD;
664 if (state->wbits == 0)
665 state->wbits = len;
666 if (len > 15 || len > state->wbits) {
672 state->mode = BAD;
675 state->dmax = 1U << len;
676 state->flags = 0; /* indicate zlib header */
678 strm->adler = state->check = adler32(0L, Z_NULL, 0);
679 state->mode = hold & 0x200 ? DICTID : TYPE;
685 state->flags = (int)(hold);
686 if ((state->flags & 0xff) != Z_DEFLATED) {
692 state->mode = BAD;
695 if (state->flags & 0xe000) {
701 state->mode = BAD;
704 if (state->head != Z_NULL)
705 state->head->text = (int)((hold >> 8) & 1);
706 if ((state->flags & 0x0200) && (state->wrap & 4))
707 CRC2(state->check, hold);
709 state->mode = TIME;
713 if (state->head != Z_NULL)
714 state->head->time = hold;
715 if ((state->flags & 0x0200) && (state->wrap & 4))
716 CRC4(state->check, hold);
718 state->mode = OS;
722 if (state->head != Z_NULL) {
723 state->head->xflags = (int)(hold & 0xff);
724 state->head->os = (int)(hold >> 8);
726 if ((state->flags & 0x0200) && (state->wrap & 4))
727 CRC2(state->check, hold);
729 state->mode = EXLEN;
732 if (state->flags & 0x0400) {
734 state->length = (unsigned)(hold);
735 if (state->head != Z_NULL)
736 state->head->extra_len = (unsigned)hold;
737 if ((state->flags & 0x0200) && (state->wrap & 4))
738 CRC2(state->check, hold);
741 else if (state->head != Z_NULL)
742 state->head->extra = Z_NULL;
743 state->mode = EXTRA;
746 if (state->flags & 0x0400) {
747 copy = state->length;
750 if (state->head != Z_NULL &&
751 state->head->extra != Z_NULL &&
752 (len = state->head->extra_len - state->length) <
753 state->head->extra_max) {
754 zmemcpy(state->head->extra + len, next,
755 len + copy > state->head->extra_max ?
756 state->head->extra_max - len : copy);
758 if ((state->flags & 0x0200) && (state->wrap & 4))
759 state->check = crc32(state->check, next, copy);
762 state->length -= copy;
764 if (state->length) goto inf_leave;
766 state->length = 0;
767 state->mode = NAME;
770 if (state->flags & 0x0800) {
775 if (state->head != Z_NULL &&
776 state->head->name != Z_NULL &&
777 state->length < state->head->name_max)
778 state->head->name[state->length++] = (Bytef)len;
780 if ((state->flags & 0x0200) && (state->wrap & 4))
781 state->check = crc32(state->check, next, copy);
786 else if (state->head != Z_NULL)
787 state->head->name = Z_NULL;
788 state->length = 0;
789 state->mode = COMMENT;
792 if (state->flags & 0x1000) {
797 if (state->head != Z_NULL &&
798 state->head->comment != Z_NULL &&
799 state->length < state->head->comm_max)
800 state->head->comment[state->length++] = (Bytef)len;
802 if ((state->flags & 0x0200) && (state->wrap & 4))
803 state->check = crc32(state->check, next, copy);
808 else if (state->head != Z_NULL)
809 state->head->comment = Z_NULL;
810 state->mode = HCRC;
813 if (state->flags & 0x0200) {
815 if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
821 state->mode = BAD;
826 if (state->head != Z_NULL) {
827 state->head->hcrc = (int)((state->flags >> 9) & 1);
828 state->head->done = 1;
830 strm->adler = state->check = crc32(0L, Z_NULL, 0);
831 state->mode = TYPE;
836 strm->adler = state->check = ZSWAP32(hold);
838 state->mode = DICT;
841 if (state->havedict == 0) {
845 strm->adler = state->check = adler32(0L, Z_NULL, 0);
846 state->mode = TYPE;
852 if (state->last) {
854 state->mode = CHECK;
858 state->last = BITS(1);
863 state->last ? " (last)" : ""));
864 state->mode = STORED;
867 fixedtables(state);
869 state->last ? " (last)" : ""));
870 state->mode = LEN_; /* decode codes */
878 state->last ? " (last)" : ""));
879 state->mode = TABLE;
887 state->mode = BAD;
900 state->mode = BAD;
903 state->length = (unsigned)hold & 0xffff;
905 state->length));
907 state->mode = COPY_;
911 state->mode = COPY;
914 copy = state->length;
924 state->length -= copy;
928 state->mode = TYPE;
932 state->nlen = BITS(5) + 257;
934 state->ndist = BITS(5) + 1;
936 state->ncode = BITS(4) + 4;
939 if (state->nlen > 286 || state->ndist > 30) {
945 state->mode = BAD;
950 state->have = 0;
951 state->mode = LENLENS;
954 while (state->have < state->ncode) {
956 state->lens[order[state->have++]] = (unsigned short)BITS(3);
959 while (state->have < 19)
960 state->lens[order[state->have++]] = 0;
961 state->next = state->codes;
962 state->lencode = state->distcode = (const code FAR *)(state->next);
963 state->lenbits = 7;
964 ret = inflate_table(CODES, state->lens, 19, &(state->next),
965 &(state->lenbits), state->work);
972 state->mode = BAD;
976 state->have = 0;
977 state->mode = CODELENS;
980 while (state->have < state->nlen + state->ndist) {
982 here = state->lencode[BITS(state->lenbits)];
988 state->lens[state->have++] = here.val;
994 if (state->have == 0) {
1000 state->mode = BAD;
1003 len = state->lens[state->have - 1];
1021 if (state->have + copy > state->nlen + state->ndist) {
1027 state->mode = BAD;
1031 state->lens[state->have++] = (unsigned short)len;
1036 if (state->mode == BAD) break;
1039 if (state->lens[256] == 0) {
1045 state->mode = BAD;
1052 state->next = state->codes;
1053 state->lencode = (const code FAR *)(state->next);
1054 state->lenbits = 9;
1055 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1056 &(state->lenbits), state->work);
1063 state->mode = BAD;
1066 state->distcode = (const code FAR *)(state->next);
1067 state->distbits = 6;
1068 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
1069 &(state->next), &(state->distbits), state->work);
1076 state->mode = BAD;
1080 state->mode = LEN_;
1084 state->mode = LEN;
1092 if (state->mode == TYPE)
1093 state->back = -1;
1097 state->back = 0;
1099 here = state->lencode[BITS(state->lenbits)];
1106 here = state->lencode[last.val +
1112 state->back += last.bits;
1115 state->back += here.bits;
1116 state->length = (unsigned)here.val;
1121 state->mode = LIT;
1126 state->back = -1;
1127 state->mode = TYPE;
1136 state->mode = BAD;
1139 state->extra = (unsigned)(here.op) & 15;
1140 state->mode = LENEXT;
1143 if (state->extra) {
1144 NEEDBITS(state->extra);
1145 state->length += BITS(state->extra);
1146 DROPBITS(state->extra);
1147 state->back += state->extra;
1149 Tracevv((stderr, "inflate: length %u\n", state->length));
1150 state->was = state->length;
1151 state->mode = DIST;
1155 here = state->distcode[BITS(state->distbits)];
1162 here = state->distcode[last.val +
1168 state->back += last.bits;
1171 state->back += here.bits;
1178 state->mode = BAD;
1181 state->offset = (unsigned)here.val;
1182 state->extra = (unsigned)(here.op) & 15;
1183 state->mode = DISTEXT;
1186 if (state->extra) {
1187 NEEDBITS(state->extra);
1188 state->offset += BITS(state->extra);
1189 DROPBITS(state->extra);
1190 state->back += state->extra;
1193 if (state->offset > state->dmax) {
1199 state->mode = BAD;
1203 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1204 state->mode = MATCH;
1209 if (state->offset > copy) { /* copy from window */
1210 copy = state->offset - copy;
1211 if (copy > state->whave) {
1212 if (state->sane) {
1218 state->mode = BAD;
1223 copy -= state->whave;
1224 if (copy > state->length) copy = state->length;
1227 state->length -= copy;
1231 if (state->length == 0) state->mode = LEN;
1235 if (copy > state->wnext) {
1236 copy -= state->wnext;
1237 from = state->window + (state->wsize - copy);
1240 from = state->window + (state->wnext - copy);
1241 if (copy > state->length) copy = state->length;
1244 from = put - state->offset;
1245 copy = state->length;
1249 state->length -= copy;
1253 if (state->length == 0) state->mode = LEN;
1257 *put++ = (unsigned char)(state->length);
1259 state->mode = LEN;
1262 if (state->wrap) {
1266 state->total += out;
1267 if ((state->wrap & 4) && out)
1268 strm->adler = state->check =
1269 UPDATE_CHECK(state->check, put - out, out);
1271 if ((state->wrap & 4) && (
1273 state->flags ? hold :
1275 ZSWAP32(hold)) != state->check) {
1281 state->mode = BAD;
1288 state->mode = LENGTH;
1291 if (state->wrap && state->flags) {
1293 if ((state->wrap & 4) && hold != (state->total & 0xffffffff)) {
1299 state->mode = BAD;
1306 state->mode = DONE;
1325 error. Call updatewindow() to create and/or update the window state.
1330 if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
1331 (state->mode < CHECK || flush != Z_FINISH)))
1333 state->mode = MEM;
1340 state->total += out;
1341 if ((state->wrap & 4) && out)
1342 strm->adler = state->check =
1343 UPDATE_CHECK(state->check, strm->next_out - out, out);
1344 strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
1345 (state->mode == TYPE ? 128 : 0) +
1346 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1353 struct inflate_state FAR *state;
1356 state = (struct inflate_state FAR *)strm->state;
1357 if (state->window != Z_NULL) ZFREE(strm, state->window, 1U << state->wbits);
1358 ZFREE(strm, strm->state, sizeof(struct inflate_state));
1359 strm->state = Z_NULL;
1366 struct inflate_state FAR *state;
1368 /* check state */
1370 state = (struct inflate_state FAR *)strm->state;
1373 if (state->whave && dictionary != Z_NULL) {
1374 zmemcpy(dictionary, state->window + state->wnext,
1375 state->whave - state->wnext);
1376 zmemcpy(dictionary + state->whave - state->wnext,
1377 state->window, state->wnext);
1380 *dictLength = state->whave;
1386 struct inflate_state FAR *state;
1390 /* check state */
1392 state = (struct inflate_state FAR *)strm->state;
1393 if (state->wrap != 0 && state->mode != DICT)
1397 if (state->mode == DICT) {
1400 if (dictid != state->check)
1408 state->mode = MEM;
1411 state->havedict = 1;
1417 struct inflate_state FAR *state;
1419 /* check state */
1421 state = (struct inflate_state FAR *)strm->state;
1422 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1425 state->head = head;
1434 state. If on return *have equals four, then the pattern was found and the
1438 called again with more data and the *have state. *have is initialized to
1466 struct inflate_state FAR *state;
1470 state = (struct inflate_state FAR *)strm->state;
1471 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1474 if (state->mode != SYNC) {
1475 state->mode = SYNC;
1476 state->hold >>= state->bits & 7;
1477 state->bits -= state->bits & 7;
1479 while (state->bits >= 8) {
1480 buf[len++] = (unsigned char)(state->hold);
1481 state->hold >>= 8;
1482 state->bits -= 8;
1484 state->have = 0;
1485 syncsearch(&(state->have), buf, len);
1489 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1495 if (state->have != 4) return Z_DATA_ERROR;
1496 if (state->flags == -1)
1497 state->wrap = 0; /* if no header yet, treat as raw */
1499 state->wrap &= ~4; /* no point in computing a check value now */
1500 flags = state->flags;
1504 state->flags = flags;
1505 state->mode = TYPE;
1518 struct inflate_state FAR *state;
1521 state = (struct inflate_state FAR *)strm->state;
1522 return state->mode == STORED && state->bits == 0;
1526 struct inflate_state FAR *state;
1534 state = (struct inflate_state FAR *)source->state;
1541 if (state->window != Z_NULL) {
1543 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1550 /* copy state */
1552 zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1554 if (state->lencode >= state->codes &&
1555 state->lencode <= state->codes + ENOUGH - 1) {
1556 copy->lencode = copy->codes + (state->lencode - state->codes);
1557 copy->distcode = copy->codes + (state->distcode - state->codes);
1559 copy->next = copy->codes + (state->next - state->codes);
1561 wsize = 1U << state->wbits;
1562 zmemcpy(window, state->window, wsize);
1565 dest->state = (struct internal_state FAR *)copy;
1570 struct inflate_state FAR *state;
1573 state = (struct inflate_state FAR *)strm->state;
1575 state->sane = !subvert;
1579 state->sane = 1;
1585 struct inflate_state FAR *state;
1588 state = (struct inflate_state FAR *)strm->state;
1589 if (check && state->wrap)
1590 state->wrap |= 4;
1592 state->wrap &= ~4;
1597 struct inflate_state FAR *state;
1601 state = (struct inflate_state FAR *)strm->state;
1602 return (long)(((unsigned long)((long)state->back)) << 16) +
1603 (state->mode == COPY ? state->length :
1604 (state->mode == MATCH ? state->was - state->length : 0));
1608 struct inflate_state FAR *state;
1610 state = (struct inflate_state FAR *)strm->state;
1611 return (unsigned long)(state->next - state->codes);