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 local void fixedtables OF((struct inflate_state FAR *state));
107 struct inflate_state FAR *state;
111 state = (struct inflate_state FAR *)strm->state;
112 if (state == Z_NULL || state->strm != strm ||
113 state->mode < HEAD || state->mode > SYNC)
120 struct inflate_state FAR *state;
123 state = (struct inflate_state FAR *)strm->state;
124 strm->total_in = strm->total_out = state->total = 0;
126 if (state->wrap) /* to support ill-conceived Java test suite */
127 strm->adler = state->wrap & 1;
128 state->mode = HEAD;
129 state->last = 0;
130 state->havedict = 0;
131 state->flags = -1;
132 state->dmax = 32768U;
133 state->head = Z_NULL;
134 state->hold = 0;
135 state->bits = 0;
136 state->lencode = state->distcode = state->next = state->codes;
137 state->sane = 1;
138 state->back = -1;
145 struct inflate_state FAR *state;
148 state = (struct inflate_state FAR *)strm->state;
149 state->wsize = 0;
150 state->whave = 0;
151 state->wnext = 0;
158 struct inflate_state FAR *state;
160 /* get the state */
162 state = (struct inflate_state FAR *)strm->state;
180 if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
181 ZFREE(strm, state->window);
182 state->window = Z_NULL;
185 /* update state and reset the rest of it */
186 state->wrap = wrap;
187 state->wbits = (unsigned)windowBits;
195 struct inflate_state FAR *state;
216 state = (struct inflate_state FAR *)
218 if (state == Z_NULL) return Z_MEM_ERROR;
220 strm->state = (struct internal_state FAR *)state;
221 state->strm = strm;
222 state->window = Z_NULL;
223 state->mode = HEAD; /* to pass state test in inflateReset2() */
226 ZFREE(strm, state);
227 strm->state = Z_NULL;
239 struct inflate_state FAR *state;
242 state = (struct inflate_state FAR *)strm->state;
244 state->hold = 0;
245 state->bits = 0;
248 if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR;
250 state->hold += (unsigned)value << state->bits;
251 state->bits += (uInt)bits;
256 Return state with length and distance decoding tables and index sizes set to
265 local void fixedtables(struct inflate_state FAR *state)
279 while (sym < 144) state->lens[sym++] = 8;
280 while (sym < 256) state->lens[sym++] = 9;
281 while (sym < 280) state->lens[sym++] = 7;
282 while (sym < 288) state->lens[sym++] = 8;
286 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
290 while (sym < 32) state->lens[sym++] = 5;
293 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
301 state->lencode = lenfix;
302 state->lenbits = 9;
303 state->distcode = distfix;
304 state->distbits = 5;
331 struct inflate_state state;
333 fixedtables(&state);
348 printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
349 state.lencode[low].bits, state.lencode[low].val);
359 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
360 state.distcode[low].val);
384 struct inflate_state FAR *state;
387 state = (struct inflate_state FAR *)strm->state;
390 if (state->window == Z_NULL) {
391 state->window = (unsigned char FAR *)
392 ZALLOC(strm, 1U << state->wbits,
394 if (state->window == Z_NULL) return 1;
398 if (state->wsize == 0) {
399 state->wsize = 1U << state->wbits;
400 state->wnext = 0;
401 state->whave = 0;
404 /* copy state->wsize or less output bytes into the circular window */
405 if (copy >= state->wsize) {
406 zmemcpy(state->window, end - state->wsize, state->wsize);
407 state->wnext = 0;
408 state->whave = state->wsize;
411 dist = state->wsize - state->wnext;
413 zmemcpy(state->window + state->wnext, end - copy, dist);
416 zmemcpy(state->window, end - copy, copy);
417 state->wnext = copy;
418 state->whave = state->wsize;
421 state->wnext += dist;
422 if (state->wnext == state->wsize) state->wnext = 0;
423 if (state->whave < state->wsize) state->whave += dist;
434 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
458 /* Load registers with state in inflate() for speed */
465 hold = state->hold; \
466 bits = state->bits; \
469 /* Restore state from registers in inflate() */
476 state->hold = hold; \
477 state->bits = bits; \
524 inflate() uses a state machine to process as much input data and generate as
525 much output data as possible before returning. The state machine is
528 for (;;) switch (state) {
534 state = STATEm;
541 next state. The NEEDBITS() macro is usually the way the state evaluates
564 state information is maintained to continue the loop where it left off
566 would all have to actually be part of the saved state in case NEEDBITS()
575 state = STATEx;
578 As shown above, if the next state is also the next case, then the break
581 A state may also return if there is not enough output space available to
582 complete that state. Those states are copying stored data, writing a
607 struct inflate_state FAR *state;
630 state = (struct inflate_state FAR *)strm->state;
631 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
637 switch (state->mode) {
639 if (state->wrap == 0) {
640 state->mode = TYPEDO;
645 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
646 if (state->wbits == 0)
647 state->wbits = 15;
648 state->check = crc32(0L, Z_NULL, 0);
649 CRC2(state->check, hold);
651 state->mode = FLAGS;
654 if (state->head != Z_NULL)
655 state->head->done = -1;
656 if (!(state->wrap & 1) || /* check if zlib header allowed */
662 state->mode = BAD;
667 state->mode = BAD;
672 if (state->wbits == 0)
673 state->wbits = len;
674 if (len > 15 || len > state->wbits) {
676 state->mode = BAD;
679 state->dmax = 1U << len;
680 state->flags = 0; /* indicate zlib header */
682 strm->adler = state->check = adler32(0L, Z_NULL, 0);
683 state->mode = hold & 0x200 ? DICTID : TYPE;
689 state->flags = (int)(hold);
690 if ((state->flags & 0xff) != Z_DEFLATED) {
692 state->mode = BAD;
695 if (state->flags & 0xe000) {
697 state->mode = BAD;
700 if (state->head != Z_NULL)
701 state->head->text = (int)((hold >> 8) & 1);
702 if ((state->flags & 0x0200) && (state->wrap & 4))
703 CRC2(state->check, hold);
705 state->mode = TIME;
709 if (state->head != Z_NULL)
710 state->head->time = hold;
711 if ((state->flags & 0x0200) && (state->wrap & 4))
712 CRC4(state->check, hold);
714 state->mode = OS;
718 if (state->head != Z_NULL) {
719 state->head->xflags = (int)(hold & 0xff);
720 state->head->os = (int)(hold >> 8);
722 if ((state->flags & 0x0200) && (state->wrap & 4))
723 CRC2(state->check, hold);
725 state->mode = EXLEN;
728 if (state->flags & 0x0400) {
730 state->length = (unsigned)(hold);
731 if (state->head != Z_NULL)
732 state->head->extra_len = (unsigned)hold;
733 if ((state->flags & 0x0200) && (state->wrap & 4))
734 CRC2(state->check, hold);
737 else if (state->head != Z_NULL)
738 state->head->extra = Z_NULL;
739 state->mode = EXTRA;
742 if (state->flags & 0x0400) {
743 copy = state->length;
746 if (state->head != Z_NULL &&
747 state->head->extra != Z_NULL &&
748 (len = state->head->extra_len - state->length) <
749 state->head->extra_max) {
750 zmemcpy(state->head->extra + len, next,
751 len + copy > state->head->extra_max ?
752 state->head->extra_max - len : copy);
754 if ((state->flags & 0x0200) && (state->wrap & 4))
755 state->check = crc32(state->check, next, copy);
758 state->length -= copy;
760 if (state->length) goto inf_leave;
762 state->length = 0;
763 state->mode = NAME;
766 if (state->flags & 0x0800) {
771 if (state->head != Z_NULL &&
772 state->head->name != Z_NULL &&
773 state->length < state->head->name_max)
774 state->head->name[state->length++] = (Bytef)len;
776 if ((state->flags & 0x0200) && (state->wrap & 4))
777 state->check = crc32(state->check, next, copy);
782 else if (state->head != Z_NULL)
783 state->head->name = Z_NULL;
784 state->length = 0;
785 state->mode = COMMENT;
788 if (state->flags & 0x1000) {
793 if (state->head != Z_NULL &&
794 state->head->comment != Z_NULL &&
795 state->length < state->head->comm_max)
796 state->head->comment[state->length++] = (Bytef)len;
798 if ((state->flags & 0x0200) && (state->wrap & 4))
799 state->check = crc32(state->check, next, copy);
804 else if (state->head != Z_NULL)
805 state->head->comment = Z_NULL;
806 state->mode = HCRC;
809 if (state->flags & 0x0200) {
811 if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
813 state->mode = BAD;
818 if (state->head != Z_NULL) {
819 state->head->hcrc = (int)((state->flags >> 9) & 1);
820 state->head->done = 1;
822 strm->adler = state->check = crc32(0L, Z_NULL, 0);
823 state->mode = TYPE;
828 strm->adler = state->check = ZSWAP32(hold);
830 state->mode = DICT;
833 if (state->havedict == 0) {
837 strm->adler = state->check = adler32(0L, Z_NULL, 0);
838 state->mode = TYPE;
844 if (state->last) {
846 state->mode = CHECK;
850 state->last = BITS(1);
855 state->last ? " (last)" : ""));
856 state->mode = STORED;
859 fixedtables(state);
861 state->last ? " (last)" : ""));
862 state->mode = LEN_; /* decode codes */
870 state->last ? " (last)" : ""));
871 state->mode = TABLE;
875 state->mode = BAD;
884 state->mode = BAD;
887 state->length = (unsigned)hold & 0xffff;
889 state->length));
891 state->mode = COPY_;
895 state->mode = COPY;
898 copy = state->length;
908 state->length -= copy;
912 state->mode = TYPE;
916 state->nlen = BITS(5) + 257;
918 state->ndist = BITS(5) + 1;
920 state->ncode = BITS(4) + 4;
923 if (state->nlen > 286 || state->ndist > 30) {
925 state->mode = BAD;
930 state->have = 0;
931 state->mode = LENLENS;
934 while (state->have < state->ncode) {
936 state->lens[order[state->have++]] = (unsigned short)BITS(3);
939 while (state->have < 19)
940 state->lens[order[state->have++]] = 0;
941 state->next = state->codes;
942 state->lencode = (const code FAR *)(state->next);
943 state->lenbits = 7;
944 ret = inflate_table(CODES, state->lens, 19, &(state->next),
945 &(state->lenbits), state->work);
948 state->mode = BAD;
952 state->have = 0;
953 state->mode = CODELENS;
956 while (state->have < state->nlen + state->ndist) {
958 here = state->lencode[BITS(state->lenbits)];
964 state->lens[state->have++] = here.val;
970 if (state->have == 0) {
972 state->mode = BAD;
975 len = state->lens[state->have - 1];
993 if (state->have + copy > state->nlen + state->ndist) {
995 state->mode = BAD;
999 state->lens[state->have++] = (unsigned short)len;
1004 if (state->mode == BAD) break;
1007 if (state->lens[256] == 0) {
1009 state->mode = BAD;
1016 state->next = state->codes;
1017 state->lencode = (const code FAR *)(state->next);
1018 state->lenbits = 9;
1019 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1020 &(state->lenbits), state->work);
1023 state->mode = BAD;
1026 state->distcode = (const code FAR *)(state->next);
1027 state->distbits = 6;
1028 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
1029 &(state->next), &(state->distbits), state->work);
1032 state->mode = BAD;
1036 state->mode = LEN_;
1040 state->mode = LEN;
1047 if (state->mode == TYPE)
1048 state->back = -1;
1051 state->back = 0;
1053 here = state->lencode[BITS(state->lenbits)];
1060 here = state->lencode[last.val +
1066 state->back += last.bits;
1069 state->back += here.bits;
1070 state->length = (unsigned)here.val;
1075 state->mode = LIT;
1080 state->back = -1;
1081 state->mode = TYPE;
1086 state->mode = BAD;
1089 state->extra = (unsigned)(here.op) & 15;
1090 state->mode = LENEXT;
1093 if (state->extra) {
1094 NEEDBITS(state->extra);
1095 state->length += BITS(state->extra);
1096 DROPBITS(state->extra);
1097 state->back += state->extra;
1099 Tracevv((stderr, "inflate: length %u\n", state->length));
1100 state->was = state->length;
1101 state->mode = DIST;
1105 here = state->distcode[BITS(state->distbits)];
1112 here = state->distcode[last.val +
1118 state->back += last.bits;
1121 state->back += here.bits;
1124 state->mode = BAD;
1127 state->offset = (unsigned)here.val;
1128 state->extra = (unsigned)(here.op) & 15;
1129 state->mode = DISTEXT;
1132 if (state->extra) {
1133 NEEDBITS(state->extra);
1134 state->offset += BITS(state->extra);
1135 DROPBITS(state->extra);
1136 state->back += state->extra;
1139 if (state->offset > state->dmax) {
1141 state->mode = BAD;
1145 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1146 state->mode = MATCH;
1151 if (state->offset > copy) { /* copy from window */
1152 copy = state->offset - copy;
1153 if (copy > state->whave) {
1154 if (state->sane) {
1156 state->mode = BAD;
1161 copy -= state->whave;
1162 if (copy > state->length) copy = state->length;
1165 state->length -= copy;
1169 if (state->length == 0) state->mode = LEN;
1173 if (copy > state->wnext) {
1174 copy -= state->wnext;
1175 from = state->window + (state->wsize - copy);
1178 from = state->window + (state->wnext - copy);
1179 if (copy > state->length) copy = state->length;
1182 from = put - state->offset;
1183 copy = state->length;
1187 state->length -= copy;
1191 if (state->length == 0) state->mode = LEN;
1195 *put++ = (unsigned char)(state->length);
1197 state->mode = LEN;
1200 if (state->wrap) {
1204 state->total += out;
1205 if ((state->wrap & 4) && out)
1206 strm->adler = state->check =
1207 UPDATE_CHECK(state->check, put - out, out);
1209 if ((state->wrap & 4) && (
1211 state->flags ? hold :
1213 ZSWAP32(hold)) != state->check) {
1215 state->mode = BAD;
1222 state->mode = LENGTH;
1225 if (state->wrap && state->flags) {
1227 if ((state->wrap & 4) && hold != (state->total & 0xffffffff)) {
1229 state->mode = BAD;
1236 state->mode = DONE;
1255 error. Call updatewindow() to create and/or update the window state.
1260 if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
1261 (state->mode < CHECK || flush != Z_FINISH)))
1263 state->mode = MEM;
1270 state->total += out;
1271 if ((state->wrap & 4) && out)
1272 strm->adler = state->check =
1273 UPDATE_CHECK(state->check, strm->next_out - out, out);
1274 strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
1275 (state->mode == TYPE ? 128 : 0) +
1276 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1284 struct inflate_state FAR *state;
1287 state = (struct inflate_state FAR *)strm->state;
1288 if (state->window != Z_NULL) ZFREE(strm, state->window);
1289 ZFREE(strm, strm->state);
1290 strm->state = Z_NULL;
1298 struct inflate_state FAR *state;
1300 /* check state */
1302 state = (struct inflate_state FAR *)strm->state;
1305 if (state->whave && dictionary != Z_NULL) {
1306 zmemcpy(dictionary, state->window + state->wnext,
1307 state->whave - state->wnext);
1308 zmemcpy(dictionary + state->whave - state->wnext,
1309 state->window, state->wnext);
1312 *dictLength = state->whave;
1319 struct inflate_state FAR *state;
1323 /* check state */
1325 state = (struct inflate_state FAR *)strm->state;
1326 if (state->wrap != 0 && state->mode != DICT)
1330 if (state->mode == DICT) {
1333 if (dictid != state->check)
1341 state->mode = MEM;
1344 state->havedict = 1;
1351 struct inflate_state FAR *state;
1353 /* check state */
1355 state = (struct inflate_state FAR *)strm->state;
1356 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1359 state->head = head;
1368 state. If on return *have equals four, then the pattern was found and the
1372 called again with more data and the *have state. *have is initialized to
1402 struct inflate_state FAR *state;
1406 state = (struct inflate_state FAR *)strm->state;
1407 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1410 if (state->mode != SYNC) {
1411 state->mode = SYNC;
1412 state->hold <<= state->bits & 7;
1413 state->bits -= state->bits & 7;
1415 while (state->bits >= 8) {
1416 buf[len++] = (unsigned char)(state->hold);
1417 state->hold >>= 8;
1418 state->bits -= 8;
1420 state->have = 0;
1421 syncsearch(&(state->have), buf, len);
1425 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1431 if (state->have != 4) return Z_DATA_ERROR;
1432 if (state->flags == -1)
1433 state->wrap = 0; /* if no header yet, treat as raw */
1435 state->wrap &= ~4; /* no point in computing a check value now */
1436 flags = state->flags;
1440 state->flags = flags;
1441 state->mode = TYPE;
1455 struct inflate_state FAR *state;
1458 state = (struct inflate_state FAR *)strm->state;
1459 return state->mode == STORED && state->bits == 0;
1464 struct inflate_state FAR *state;
1472 state = (struct inflate_state FAR *)source->state;
1479 if (state->window != Z_NULL) {
1481 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1488 /* copy state */
1490 zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1492 if (state->lencode >= state->codes &&
1493 state->lencode <= state->codes + ENOUGH - 1) {
1494 copy->lencode = copy->codes + (state->lencode - state->codes);
1495 copy->distcode = copy->codes + (state->distcode - state->codes);
1497 copy->next = copy->codes + (state->next - state->codes);
1499 wsize = 1U << state->wbits;
1500 zmemcpy(window, state->window, wsize);
1503 dest->state = (struct internal_state FAR *)copy;
1509 struct inflate_state FAR *state;
1512 state = (struct inflate_state FAR *)strm->state;
1514 state->sane = !subvert;
1518 state->sane = 1;
1525 struct inflate_state FAR *state;
1528 state = (struct inflate_state FAR *)strm->state;
1529 if (check && state->wrap)
1530 state->wrap |= 4;
1532 state->wrap &= ~4;
1538 struct inflate_state FAR *state;
1542 state = (struct inflate_state FAR *)strm->state;
1543 return (long)(((unsigned long)((long)state->back)) << 16) +
1544 (state->mode == COPY ? state->length :
1545 (state->mode == MATCH ? state->was - state->length : 0));
1550 struct inflate_state FAR *state;
1552 state = (struct inflate_state FAR *)strm->state;
1553 return (unsigned long)(state->next - state->codes);