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);
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);
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) {
673 state->mode = BAD;
676 state->dmax = 1U << len;
677 state->flags = 0; /* indicate zlib header */
679 strm->adler = state->check = adler32(0L, Z_NULL, 0);
680 state->mode = hold & 0x200 ? DICTID : TYPE;
686 state->flags = (int)(hold);
687 if ((state->flags & 0xff) != Z_DEFLATED) {
693 state->mode = BAD;
696 if (state->flags & 0xe000) {
702 state->mode = BAD;
705 if (state->head != Z_NULL)
706 state->head->text = (int)((hold >> 8) & 1);
707 if ((state->flags & 0x0200) && (state->wrap & 4))
708 CRC2(state->check, hold);
710 state->mode = TIME;
714 if (state->head != Z_NULL)
715 state->head->time = hold;
716 if ((state->flags & 0x0200) && (state->wrap & 4))
717 CRC4(state->check, hold);
719 state->mode = OS;
723 if (state->head != Z_NULL) {
724 state->head->xflags = (int)(hold & 0xff);
725 state->head->os = (int)(hold >> 8);
727 if ((state->flags & 0x0200) && (state->wrap & 4))
728 CRC2(state->check, hold);
730 state->mode = EXLEN;
733 if (state->flags & 0x0400) {
735 state->length = (unsigned)(hold);
736 if (state->head != Z_NULL)
737 state->head->extra_len = (unsigned)hold;
738 if ((state->flags & 0x0200) && (state->wrap & 4))
739 CRC2(state->check, hold);
742 else if (state->head != Z_NULL)
743 state->head->extra = Z_NULL;
744 state->mode = EXTRA;
747 if (state->flags & 0x0400) {
748 copy = state->length;
751 if (state->head != Z_NULL &&
752 state->head->extra != Z_NULL &&
753 (len = state->head->extra_len - state->length) <
754 state->head->extra_max) {
755 zmemcpy(state->head->extra + len, next,
756 len + copy > state->head->extra_max ?
757 state->head->extra_max - len : copy);
759 if ((state->flags & 0x0200) && (state->wrap & 4))
760 state->check = crc32(state->check, next, copy);
763 state->length -= copy;
765 if (state->length) goto inf_leave;
767 state->length = 0;
768 state->mode = NAME;
771 if (state->flags & 0x0800) {
776 if (state->head != Z_NULL &&
777 state->head->name != Z_NULL &&
778 state->length < state->head->name_max)
779 state->head->name[state->length++] = (Bytef)len;
781 if ((state->flags & 0x0200) && (state->wrap & 4))
782 state->check = crc32(state->check, next, copy);
787 else if (state->head != Z_NULL)
788 state->head->name = Z_NULL;
789 state->length = 0;
790 state->mode = COMMENT;
793 if (state->flags & 0x1000) {
798 if (state->head != Z_NULL &&
799 state->head->comment != Z_NULL &&
800 state->length < state->head->comm_max)
801 state->head->comment[state->length++] = (Bytef)len;
803 if ((state->flags & 0x0200) && (state->wrap & 4))
804 state->check = crc32(state->check, next, copy);
809 else if (state->head != Z_NULL)
810 state->head->comment = Z_NULL;
811 state->mode = HCRC;
814 if (state->flags & 0x0200) {
816 if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
822 state->mode = BAD;
827 if (state->head != Z_NULL) {
828 state->head->hcrc = (int)((state->flags >> 9) & 1);
829 state->head->done = 1;
831 strm->adler = state->check = crc32(0L, Z_NULL, 0);
832 state->mode = TYPE;
837 strm->adler = state->check = ZSWAP32(hold);
839 state->mode = DICT;
842 if (state->havedict == 0) {
846 strm->adler = state->check = adler32(0L, Z_NULL, 0);
847 state->mode = TYPE;
853 if (state->last) {
855 state->mode = CHECK;
859 state->last = BITS(1);
864 state->last ? " (last)" : ""));
865 state->mode = STORED;
868 fixedtables(state);
870 state->last ? " (last)" : ""));
871 state->mode = LEN_; /* decode codes */
879 state->last ? " (last)" : ""));
880 state->mode = TABLE;
888 state->mode = BAD;
901 state->mode = BAD;
904 state->length = (unsigned)hold & 0xffff;
906 state->length));
908 state->mode = COPY_;
912 state->mode = COPY;
915 copy = state->length;
925 state->length -= copy;
929 state->mode = TYPE;
933 state->nlen = BITS(5) + 257;
935 state->ndist = BITS(5) + 1;
937 state->ncode = BITS(4) + 4;
940 if (state->nlen > 286 || state->ndist > 30) {
946 state->mode = BAD;
951 state->have = 0;
952 state->mode = LENLENS;
955 while (state->have < state->ncode) {
957 state->lens[order[state->have++]] = (unsigned short)BITS(3);
960 while (state->have < 19)
961 state->lens[order[state->have++]] = 0;
962 state->next = state->codes;
963 state->lencode = state->distcode = (const code FAR *)(state->next);
964 state->lenbits = 7;
965 ret = inflate_table(CODES, state->lens, 19, &(state->next),
966 &(state->lenbits), state->work);
973 state->mode = BAD;
977 state->have = 0;
978 state->mode = CODELENS;
981 while (state->have < state->nlen + state->ndist) {
983 here = state->lencode[BITS(state->lenbits)];
989 state->lens[state->have++] = here.val;
995 if (state->have == 0) {
1001 state->mode = BAD;
1004 len = state->lens[state->have - 1];
1022 if (state->have + copy > state->nlen + state->ndist) {
1028 state->mode = BAD;
1032 state->lens[state->have++] = (unsigned short)len;
1037 if (state->mode == BAD) break;
1040 if (state->lens[256] == 0) {
1046 state->mode = BAD;
1053 state->next = state->codes;
1054 state->lencode = (const code FAR *)(state->next);
1055 state->lenbits = 9;
1056 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1057 &(state->lenbits), state->work);
1064 state->mode = BAD;
1067 state->distcode = (const code FAR *)(state->next);
1068 state->distbits = 6;
1069 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
1070 &(state->next), &(state->distbits), state->work);
1077 state->mode = BAD;
1081 state->mode = LEN_;
1085 state->mode = LEN;
1093 if (state->mode == TYPE)
1094 state->back = -1;
1098 state->back = 0;
1100 here = state->lencode[BITS(state->lenbits)];
1107 here = state->lencode[last.val +
1113 state->back += last.bits;
1116 state->back += here.bits;
1117 state->length = (unsigned)here.val;
1122 state->mode = LIT;
1127 state->back = -1;
1128 state->mode = TYPE;
1137 state->mode = BAD;
1140 state->extra = (unsigned)(here.op) & 15;
1141 state->mode = LENEXT;
1144 if (state->extra) {
1145 NEEDBITS(state->extra);
1146 state->length += BITS(state->extra);
1147 DROPBITS(state->extra);
1148 state->back += state->extra;
1150 Tracevv((stderr, "inflate: length %u\n", state->length));
1151 state->was = state->length;
1152 state->mode = DIST;
1156 here = state->distcode[BITS(state->distbits)];
1163 here = state->distcode[last.val +
1169 state->back += last.bits;
1172 state->back += here.bits;
1179 state->mode = BAD;
1182 state->offset = (unsigned)here.val;
1183 state->extra = (unsigned)(here.op) & 15;
1184 state->mode = DISTEXT;
1187 if (state->extra) {
1188 NEEDBITS(state->extra);
1189 state->offset += BITS(state->extra);
1190 DROPBITS(state->extra);
1191 state->back += state->extra;
1194 if (state->offset > state->dmax) {
1200 state->mode = BAD;
1204 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1205 state->mode = MATCH;
1210 if (state->offset > copy) { /* copy from window */
1211 copy = state->offset - copy;
1212 if (copy > state->whave) {
1213 if (state->sane) {
1219 state->mode = BAD;
1224 copy -= state->whave;
1225 if (copy > state->length) copy = state->length;
1228 state->length -= copy;
1232 if (state->length == 0) state->mode = LEN;
1236 if (copy > state->wnext) {
1237 copy -= state->wnext;
1238 from = state->window + (state->wsize - copy);
1241 from = state->window + (state->wnext - copy);
1242 if (copy > state->length) copy = state->length;
1245 from = put - state->offset;
1246 copy = state->length;
1250 state->length -= copy;
1254 if (state->length == 0) state->mode = LEN;
1258 *put++ = (unsigned char)(state->length);
1260 state->mode = LEN;
1263 if (state->wrap) {
1267 state->total += out;
1268 if ((state->wrap & 4) && out)
1269 strm->adler = state->check =
1270 UPDATE_CHECK(state->check, put - out, out);
1272 if ((state->wrap & 4) && (
1274 state->flags ? hold :
1276 ZSWAP32(hold)) != state->check) {
1282 state->mode = BAD;
1289 state->mode = LENGTH;
1292 if (state->wrap && state->flags) {
1294 if ((state->wrap & 4) && hold != (state->total & 0xffffffff)) {
1300 state->mode = BAD;
1307 state->mode = DONE;
1326 error. Call updatewindow() to create and/or update the window state.
1331 if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
1332 (state->mode < CHECK || flush != Z_FINISH)))
1334 state->mode = MEM;
1341 state->total += out;
1342 if ((state->wrap & 4) && out)
1343 strm->adler = state->check =
1344 UPDATE_CHECK(state->check, strm->next_out - out, out);
1345 strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
1346 (state->mode == TYPE ? 128 : 0) +
1347 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1354 struct inflate_state FAR *state;
1357 state = (struct inflate_state FAR *)strm->state;
1358 if (state->window != Z_NULL) ZFREE(strm, state->window);
1359 ZFREE(strm, strm->state);
1360 strm->state = Z_NULL;
1367 struct inflate_state FAR *state;
1369 /* check state */
1371 state = (struct inflate_state FAR *)strm->state;
1374 if (state->whave && dictionary != Z_NULL) {
1375 zmemcpy(dictionary, state->window + state->wnext,
1376 state->whave - state->wnext);
1377 zmemcpy(dictionary + state->whave - state->wnext,
1378 state->window, state->wnext);
1381 *dictLength = state->whave;
1387 struct inflate_state FAR *state;
1391 /* check state */
1393 state = (struct inflate_state FAR *)strm->state;
1394 if (state->wrap != 0 && state->mode != DICT)
1398 if (state->mode == DICT) {
1401 if (dictid != state->check)
1409 state->mode = MEM;
1412 state->havedict = 1;
1418 struct inflate_state FAR *state;
1420 /* check state */
1422 state = (struct inflate_state FAR *)strm->state;
1423 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1426 state->head = head;
1435 state. If on return *have equals four, then the pattern was found and the
1439 called again with more data and the *have state. *have is initialized to
1467 struct inflate_state FAR *state;
1471 state = (struct inflate_state FAR *)strm->state;
1472 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1475 if (state->mode != SYNC) {
1476 state->mode = SYNC;
1477 state->hold >>= state->bits & 7;
1478 state->bits -= state->bits & 7;
1480 while (state->bits >= 8) {
1481 buf[len++] = (unsigned char)(state->hold);
1482 state->hold >>= 8;
1483 state->bits -= 8;
1485 state->have = 0;
1486 syncsearch(&(state->have), buf, len);
1490 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1496 if (state->have != 4) return Z_DATA_ERROR;
1497 if (state->flags == -1)
1498 state->wrap = 0; /* if no header yet, treat as raw */
1500 state->wrap &= ~4; /* no point in computing a check value now */
1501 flags = state->flags;
1505 state->flags = flags;
1506 state->mode = TYPE;
1519 struct inflate_state FAR *state;
1522 state = (struct inflate_state FAR *)strm->state;
1523 return state->mode == STORED && state->bits == 0;
1527 struct inflate_state FAR *state;
1535 state = (struct inflate_state FAR *)source->state;
1542 if (state->window != Z_NULL) {
1544 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1551 /* copy state */
1553 zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1555 if (state->lencode >= state->codes &&
1556 state->lencode <= state->codes + ENOUGH - 1) {
1557 copy->lencode = copy->codes + (state->lencode - state->codes);
1558 copy->distcode = copy->codes + (state->distcode - state->codes);
1560 copy->next = copy->codes + (state->next - state->codes);
1562 wsize = 1U << state->wbits;
1563 zmemcpy(window, state->window, wsize);
1566 dest->state = (struct internal_state FAR *)copy;
1571 struct inflate_state FAR *state;
1574 state = (struct inflate_state FAR *)strm->state;
1576 state->sane = !subvert;
1580 state->sane = 1;
1586 struct inflate_state FAR *state;
1589 state = (struct inflate_state FAR *)strm->state;
1590 if (check && state->wrap)
1591 state->wrap |= 4;
1593 state->wrap &= ~4;
1598 struct inflate_state FAR *state;
1602 state = (struct inflate_state FAR *)strm->state;
1603 return (long)(((unsigned long)((long)state->back)) << 16) +
1604 (state->mode == COPY ? state->length :
1605 (state->mode == MATCH ? state->was - state->length : 0));
1609 struct inflate_state FAR *state;
1611 state = (struct inflate_state FAR *)strm->state;
1612 return (unsigned long)(state->next - state->codes);