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
96 struct inflate_state FAR *state;
100 state = (struct inflate_state FAR *)strm->state;
101 if (state == Z_NULL || state->strm != strm ||
102 state->mode < HEAD || state->mode > SYNC)
108 struct inflate_state FAR *state;
111 state = (struct inflate_state FAR *)strm->state;
112 strm->total_in = strm->total_out = state->total = 0;
114 if (state->wrap) /* to support ill-conceived Java test suite */
115 strm->adler = state->wrap & 1;
116 state->mode = HEAD;
117 state->last = 0;
118 state->havedict = 0;
119 state->flags = -1;
120 state->dmax = 32768U;
121 state->head = Z_NULL;
122 state->hold = 0;
123 state->bits = 0;
124 state->lencode = state->distcode = state->next = state->codes;
125 state->sane = 1;
126 state->back = -1;
132 struct inflate_state FAR *state;
135 state = (struct inflate_state FAR *)strm->state;
136 state->wsize = 0;
137 state->whave = 0;
138 state->wnext = 0;
144 struct inflate_state FAR *state;
146 /* get the state */
148 state = (struct inflate_state FAR *)strm->state;
168 if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
169 ZFREE(strm, state->window);
170 state->window = Z_NULL;
173 /* update state and reset the rest of it */
174 state->wrap = wrap;
175 state->wbits = (unsigned)windowBits;
182 struct inflate_state FAR *state;
203 state = (struct inflate_state FAR *)
205 if (state == Z_NULL) return Z_MEM_ERROR;
207 strm->state = (struct internal_state FAR *)state;
208 state->strm = strm;
209 state->window = Z_NULL;
210 state->mode = HEAD; /* to pass state test in inflateReset2() */
213 ZFREE(strm, state);
214 strm->state = Z_NULL;
225 struct inflate_state FAR *state;
232 state = (struct inflate_state FAR *)strm->state;
234 state->hold = 0;
235 state->bits = 0;
238 if (bits > 16 || state->bits + (uInt)bits > 32)
243 state->hold += (unsigned)value << state->bits;
244 state->bits += (uInt)bits;
249 Return state with length and distance decoding tables and index sizes set to
258 local void fixedtables(struct inflate_state FAR *state) {
271 while (sym < 144) state->lens[sym++] = 8;
272 while (sym < 256) state->lens[sym++] = 9;
273 while (sym < 280) state->lens[sym++] = 7;
274 while (sym < 288) state->lens[sym++] = 8;
278 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
282 while (sym < 32) state->lens[sym++] = 5;
285 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
293 state->lencode = lenfix;
294 state->lenbits = 9;
295 state->distcode = distfix;
296 state->distbits = 5;
323 struct inflate_state state;
325 fixedtables(&state);
340 printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
341 state.lencode[low].bits, state.lencode[low].val);
354 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
355 state.distcode[low].val);
382 struct inflate_state FAR *state;
385 state = (struct inflate_state FAR *)strm->state;
388 if (state->window == Z_NULL) {
389 state->window = (unsigned char FAR *)
390 ZALLOC(strm, 1U << state->wbits,
392 if (state->window == Z_NULL) return 1;
396 if (state->wsize == 0) {
397 state->wsize = 1U << state->wbits;
398 state->wnext = 0;
399 state->whave = 0;
402 /* copy state->wsize or less output bytes into the circular window */
403 if (copy >= state->wsize) {
404 zmemcpy(state->window, end - state->wsize, state->wsize);
405 state->wnext = 0;
406 state->whave = state->wsize;
409 dist = state->wsize - state->wnext;
411 zmemcpy(state->window + state->wnext, end - copy, dist);
414 zmemcpy(state->window, end - copy, copy);
415 state->wnext = copy;
416 state->whave = state->wsize;
419 state->wnext += dist;
420 if (state->wnext == state->wsize) state->wnext = 0;
421 if (state->whave < state->wsize) state->whave += dist;
432 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
456 /* Load registers with state in inflate() for speed */
463 hold = state->hold; \
464 bits = state->bits; \
467 /* Restore state from registers in inflate() */
474 state->hold = hold; \
475 state->bits = bits; \
522 inflate() uses a state machine to process as much input data and generate as
523 much output data as possible before returning. The state machine is
526 for (;;) switch (state) {
532 state = STATEm;
539 next state. The NEEDBITS() macro is usually the way the state evaluates
562 state information is maintained to continue the loop where it left off
564 would all have to actually be part of the saved state in case NEEDBITS()
573 state = STATEx;
576 As shown above, if the next state is also the next case, then the break
579 A state may also return if there is not enough output space available to
580 complete that state. Those states are copying stored data, writing a
604 struct inflate_state FAR *state;
630 state = (struct inflate_state FAR *)strm->state;
631 if (state->mode == TYPE)
633 state->mode = TYPEDO; /* skip check */
640 switch (state->mode) {
642 if (state->wrap == 0) {
643 state->mode = TYPEDO;
648 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
649 if (state->wbits == 0)
650 state->wbits = 15;
651 state->check = crc32(0L, Z_NULL, 0);
652 CRC2(state->check, hold);
654 state->mode = FLAGS;
657 if (state->head != Z_NULL)
659 state->head->done = -1;
661 if (!(state->wrap & 1) || /* check if zlib header allowed */
667 state->mode = BAD;
672 state->mode = BAD;
677 if (state->wbits == 0)
679 state->wbits = len;
681 if (len > 15 || len > state->wbits) {
683 state->mode = BAD;
686 state->dmax = 1U << len;
687 state->flags = 0; /* indicate zlib header */
689 strm->adler = state->check = adler32(0L, Z_NULL, 0);
690 state->mode = hold & 0x200 ? DICTID : TYPE;
696 state->flags = (int)(hold);
697 if ((state->flags & 0xff) != Z_DEFLATED) {
699 state->mode = BAD;
702 if (state->flags & 0xe000) {
704 state->mode = BAD;
707 if (state->head != Z_NULL)
709 state->head->text = (int)((hold >> 8) & 1);
711 if ((state->flags & 0x0200) && (state->wrap & 4))
713 CRC2(state->check, hold);
716 state->mode = TIME;
720 if (state->head != Z_NULL)
722 state->head->time = hold;
724 if ((state->flags & 0x0200) && (state->wrap & 4))
726 CRC4(state->check, hold);
729 state->mode = OS;
733 if (state->head != Z_NULL) {
734 state->head->xflags = (int)(hold & 0xff);
735 state->head->os = (int)(hold >> 8);
737 if ((state->flags & 0x0200) && (state->wrap & 4))
739 CRC2(state->check, hold);
742 state->mode = EXLEN;
745 if (state->flags & 0x0400) {
747 state->length = (unsigned)(hold);
748 if (state->head != Z_NULL)
750 state->head->extra_len = (unsigned)hold;
752 if ((state->flags & 0x0200) && (state->wrap & 4))
754 CRC2(state->check, hold);
758 else if (state->head != Z_NULL)
760 state->head->extra = Z_NULL;
762 state->mode = EXTRA;
765 if (state->flags & 0x0400) {
766 copy = state->length;
772 if (state->head != Z_NULL &&
773 state->head->extra != Z_NULL &&
774 (len = state->head->extra_len - state->length) <
775 state->head->extra_max) {
776 zmemcpy(state->head->extra + len, next,
777 len + copy > state->head->extra_max ?
778 state->head->extra_max - len : copy);
780 if ((state->flags & 0x0200) && (state->wrap & 4))
782 state->check = crc32(state->check, next, copy);
786 state->length -= copy;
788 if (state->length)
793 state->length = 0;
794 state->mode = NAME;
797 if (state->flags & 0x0800) {
802 if (state->head != Z_NULL &&
803 state->head->name != Z_NULL &&
804 state->length < state->head->name_max)
805 state->head->name[state->length++] = (Bytef)len;
807 if ((state->flags & 0x0200) && (state->wrap & 4))
809 state->check = crc32(state->check, next, copy);
818 else if (state->head != Z_NULL)
820 state->head->name = Z_NULL;
822 state->length = 0;
823 state->mode = COMMENT;
826 if (state->flags & 0x1000) {
834 if (state->head != Z_NULL &&
835 state->head->comment != Z_NULL &&
836 state->length < state->head->comm_max)
838 state->head->comment[state->length++] = (Bytef)len;
841 if ((state->flags & 0x0200) && (state->wrap & 4))
843 state->check = crc32(state->check, next, copy);
852 else if (state->head != Z_NULL)
854 state->head->comment = Z_NULL;
856 state->mode = HCRC;
859 if (state->flags & 0x0200) {
861 if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
863 state->mode = BAD;
868 if (state->head != Z_NULL) {
869 state->head->hcrc = (int)((state->flags >> 9) & 1);
870 state->head->done = 1;
872 strm->adler = state->check = crc32(0L, Z_NULL, 0);
873 state->mode = TYPE;
878 strm->adler = state->check = ZSWAP32(hold);
880 state->mode = DICT;
883 if (state->havedict == 0) {
887 strm->adler = state->check = adler32(0L, Z_NULL, 0);
888 state->mode = TYPE;
897 if (state->last) {
899 state->mode = CHECK;
903 state->last = BITS(1);
908 state->last ? " (last)" : ""));
909 state->mode = STORED;
912 fixedtables(state);
914 state->last ? " (last)" : ""));
915 state->mode = LEN_; /* decode codes */
923 state->last ? " (last)" : ""));
924 state->mode = TABLE;
928 state->mode = BAD;
937 state->mode = BAD;
940 state->length = (unsigned)hold & 0xffff;
942 state->length));
944 state->mode = COPY_;
951 state->mode = COPY;
954 copy = state->length;
964 state->length -= copy;
968 state->mode = TYPE;
972 state->nlen = BITS(5) + 257;
974 state->ndist = BITS(5) + 1;
976 state->ncode = BITS(4) + 4;
979 if (state->nlen > 286 || state->ndist > 30) {
981 state->mode = BAD;
986 state->have = 0;
987 state->mode = LENLENS;
990 while (state->have < state->ncode) {
992 state->lens[order[state->have++]] = (unsigned short)BITS(3);
995 while (state->have < 19)
996 state->lens[order[state->have++]] = 0;
997 state->next = state->codes;
998 state->lencode = (const code FAR *)(state->next);
999 state->lenbits = 7;
1000 ret = inflate_table(CODES, state->lens, 19, &(state->next),
1001 &(state->lenbits), state->work);
1004 state->mode = BAD;
1008 state->have = 0;
1009 state->mode = CODELENS;
1012 while (state->have < state->nlen + state->ndist) {
1014 here = state->lencode[BITS(state->lenbits)];
1020 state->lens[state->have++] = here.val;
1026 if (state->have == 0) {
1028 state->mode = BAD;
1031 len = state->lens[state->have - 1];
1049 if (state->have + copy > state->nlen + state->ndist) {
1051 state->mode = BAD;
1055 state->lens[state->have++] = (unsigned short)len;
1060 if (state->mode == BAD)
1066 if (state->lens[256] == 0) {
1068 state->mode = BAD;
1075 state->next = state->codes;
1076 state->lencode = (const code FAR *)(state->next);
1077 state->lenbits = 9;
1078 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1079 &(state->lenbits), state->work);
1082 state->mode = BAD;
1085 state->distcode = (const code FAR *)(state->next);
1086 state->distbits = 6;
1087 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
1088 &(state->next), &(state->distbits), state->work);
1091 state->mode = BAD;
1095 state->mode = LEN_;
1102 state->mode = LEN;
1109 if (state->mode == TYPE)
1111 state->back = -1;
1115 state->back = 0;
1117 here = state->lencode[BITS(state->lenbits)];
1127 here = state->lencode[last.val +
1136 state->back += last.bits;
1139 state->back += here.bits;
1140 state->length = (unsigned)here.val;
1145 state->mode = LIT;
1150 state->back = -1;
1151 state->mode = TYPE;
1156 state->mode = BAD;
1159 state->extra = (unsigned)(here.op) & 15;
1160 state->mode = LENEXT;
1163 if (state->extra) {
1164 NEEDBITS(state->extra);
1165 state->length += BITS(state->extra);
1166 DROPBITS(state->extra);
1167 state->back += state->extra;
1169 Tracevv((stderr, "inflate: length %u\n", state->length));
1170 state->was = state->length;
1171 state->mode = DIST;
1175 here = state->distcode[BITS(state->distbits)];
1185 here = state->distcode[last.val +
1194 state->back += last.bits;
1197 state->back += here.bits;
1200 state->mode = BAD;
1203 state->offset = (unsigned)here.val;
1204 state->extra = (unsigned)(here.op) & 15;
1205 state->mode = DISTEXT;
1208 if (state->extra) {
1209 NEEDBITS(state->extra);
1210 state->offset += BITS(state->extra);
1211 DROPBITS(state->extra);
1212 state->back += state->extra;
1215 if (state->offset > state->dmax) {
1217 state->mode = BAD;
1221 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1222 state->mode = MATCH;
1230 if (state->offset > copy) { /* copy from window */
1231 copy = state->offset - copy;
1232 if (copy > state->whave) {
1233 if (state->sane) {
1235 state->mode = BAD;
1240 copy -= state->whave;
1241 if (copy > state->length)
1243 copy = state->length;
1250 state->length -= copy;
1254 if (state->length == 0)
1256 state->mode = LEN;
1261 if (copy > state->wnext) {
1262 copy -= state->wnext;
1263 from = state->window + (state->wsize - copy);
1266 from = state->window + (state->wnext - copy);
1267 if (copy > state->length)
1269 copy = state->length;
1273 from = put - state->offset;
1274 copy = state->length;
1281 state->length -= copy;
1285 if (state->length == 0)
1287 state->mode = LEN;
1295 *put++ = (unsigned char)(state->length);
1297 state->mode = LEN;
1300 if (state->wrap) {
1304 state->total += out;
1305 if ((state->wrap & 4) && out)
1307 strm->adler = state->check =
1308 UPDATE_CHECK(state->check, put - out, out);
1311 if ((state->wrap & 4) && (
1313 state->flags ? hold :
1315 ZSWAP32(hold)) != state->check) {
1317 state->mode = BAD;
1324 state->mode = LENGTH;
1327 if (state->wrap && state->flags) {
1329 if ((state->wrap & 4) && hold != (state->total & 0xffffffff)) {
1331 state->mode = BAD;
1338 state->mode = DONE;
1357 error. Call updatewindow() to create and/or update the window state.
1362 if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
1363 (state->mode < CHECK || flush != Z_FINISH)))
1365 state->mode = MEM;
1372 state->total += out;
1373 if ((state->wrap & 4) && out)
1374 strm->adler = state->check =
1375 UPDATE_CHECK(state->check, strm->next_out - out, out);
1376 strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
1377 (state->mode == TYPE ? 128 : 0) +
1378 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1387 struct inflate_state FAR *state;
1392 state = (struct inflate_state FAR *)strm->state;
1393 if (state->window != Z_NULL)
1395 ZFREE(strm, state->window);
1397 ZFREE(strm, strm->state);
1398 strm->state = Z_NULL;
1405 struct inflate_state FAR *state;
1407 /* check state */
1412 state = (struct inflate_state FAR *)strm->state;
1415 if (state->whave && dictionary != Z_NULL) {
1416 zmemcpy(dictionary, state->window + state->wnext,
1417 state->whave - state->wnext);
1418 zmemcpy(dictionary + state->whave - state->wnext,
1419 state->window, state->wnext);
1422 *dictLength = state->whave;
1428 struct inflate_state FAR *state;
1432 /* check state */
1437 state = (struct inflate_state FAR *)strm->state;
1438 if (state->wrap != 0 && state->mode != DICT)
1444 if (state->mode == DICT) {
1447 if (dictid != state->check)
1457 state->mode = MEM;
1460 state->havedict = 1;
1466 struct inflate_state FAR *state;
1468 /* check state */
1473 state = (struct inflate_state FAR *)strm->state;
1474 if ((state->wrap & 2) == 0)
1480 state->head = head;
1489 state. If on return *have equals four, then the pattern was found and the
1493 called again with more data and the *have state. *have is initialized to
1527 struct inflate_state FAR *state;
1534 state = (struct inflate_state FAR *)strm->state;
1535 if (strm->avail_in == 0 && state->bits < 8)
1541 if (state->mode != SYNC) {
1542 state->mode = SYNC;
1543 state->hold >>= state->bits & 7;
1544 state->bits -= state->bits & 7;
1546 while (state->bits >= 8) {
1547 buf[len++] = (unsigned char)(state->hold);
1548 state->hold >>= 8;
1549 state->bits -= 8;
1551 state->have = 0;
1552 syncsearch(&(state->have), buf, len);
1556 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1562 if (state->have != 4)
1566 if (state->flags == -1)
1568 state->wrap = 0; /* if no header yet, treat as raw */
1572 state->wrap &= ~4; /* no point in computing a check value now */
1574 flags = state->flags;
1578 state->flags = flags;
1579 state->mode = TYPE;
1592 struct inflate_state FAR *state;
1598 state = (struct inflate_state FAR *)strm->state;
1599 return state->mode == STORED && state->bits == 0;
1603 struct inflate_state FAR *state;
1613 state = (struct inflate_state FAR *)source->state;
1623 if (state->window != Z_NULL) {
1625 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1632 /* copy state */
1634 zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1636 if (state->lencode >= state->codes &&
1637 state->lencode <= state->codes + ENOUGH - 1) {
1638 copy->lencode = copy->codes + (state->lencode - state->codes);
1639 copy->distcode = copy->codes + (state->distcode - state->codes);
1641 copy->next = copy->codes + (state->next - state->codes);
1643 wsize = 1U << state->wbits;
1644 zmemcpy(window, state->window, wsize);
1647 dest->state = (struct internal_state FAR *)copy;
1652 struct inflate_state FAR *state;
1658 state = (struct inflate_state FAR *)strm->state;
1660 state->sane = !subvert;
1664 state->sane = 1;
1670 struct inflate_state FAR *state;
1676 state = (struct inflate_state FAR *)strm->state;
1677 if (check && state->wrap)
1679 state->wrap |= 4;
1683 state->wrap &= ~4;
1689 struct inflate_state FAR *state;
1695 state = (struct inflate_state FAR *)strm->state;
1696 return (long)(((unsigned long)((long)state->back)) << 16) +
1697 (state->mode == COPY ? state->length :
1698 (state->mode == MATCH ? state->was - state->length : 0));
1702 struct inflate_state FAR *state;
1707 state = (struct inflate_state FAR *)strm->state;
1708 return (unsigned long)(state->next - state->codes);