Lines Matching defs:state
53 * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset)
57 * - Add comments on state->bits assertion in inffast.c
122 local void fixedtables OF((struct inflate_state FAR *state));
133 struct inflate_state FAR *state;
135 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
136 state = (struct inflate_state FAR *)strm->state;
137 strm->total_in = strm->total_out = state->total = 0;
140 state->mode = HEAD;
141 state->last = 0;
142 state->havedict = 0;
143 state->dmax = 32768U;
144 state->head = Z_NULL;
145 state->wsize = 0;
146 state->whave = 0;
147 state->write = 0;
148 state->hold = 0;
149 state->bits = 0;
150 state->lencode = state->distcode = state->next = state->codes;
160 struct inflate_state FAR *state;
162 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
163 state = (struct inflate_state FAR *)strm->state;
164 if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
166 state->hold += value << state->bits;
167 state->bits += bits;
177 struct inflate_state FAR *state;
191 state = (struct inflate_state FAR *)
193 if (state == Z_NULL) return Z_MEM_ERROR;
195 strm->state = (struct internal_state FAR *)state;
197 state->wrap = 0;
201 state->wrap = (windowBits >> 4) + 1;
207 ZFREE(strm, state);
208 strm->state = Z_NULL;
211 state->wbits = (unsigned)windowBits;
212 state->window = Z_NULL;
225 Return state with length and distance decoding tables and index sizes set to
234 local void fixedtables(state)
235 struct inflate_state FAR *state;
249 while (sym < 144) state->lens[sym++] = 8;
250 while (sym < 256) state->lens[sym++] = 9;
251 while (sym < 280) state->lens[sym++] = 7;
252 while (sym < 288) state->lens[sym++] = 8;
256 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
260 while (sym < 32) state->lens[sym++] = 5;
263 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
271 state->lencode = lenfix;
272 state->lenbits = 9;
273 state->distcode = distfix;
274 state->distbits = 5;
301 struct inflate_state state;
303 fixedtables(&state);
318 printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
319 state.lencode[low].val);
329 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
330 state.distcode[low].val);
356 struct inflate_state FAR *state;
359 state = (struct inflate_state FAR *)strm->state;
362 if (state->window == Z_NULL) {
363 state->window = (unsigned char FAR *)
364 ZALLOC(strm, 1U << state->wbits,
366 if (state->window == Z_NULL) return 1;
370 if (state->wsize == 0) {
371 state->wsize = 1U << state->wbits;
372 state->write = 0;
373 state->whave = 0;
376 /* copy state->wsize or less output bytes into the circular window */
378 if (copy >= state->wsize) {
379 zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
380 state->write = 0;
381 state->whave = state->wsize;
384 dist = state->wsize - state->write;
386 zmemcpy(state->window + state->write, strm->next_out - copy, dist);
389 zmemcpy(state->window, strm->next_out - copy, copy);
390 state->write = copy;
391 state->whave = state->wsize;
394 state->write += dist;
395 if (state->write == state->wsize) state->write = 0;
396 if (state->whave < state->wsize) state->whave += dist;
407 (state->flags ? z_crc32(check, buf, len) : adler32(check, buf, len))
431 /* Load registers with state in inflate() for speed */
438 hold = state->hold; \
439 bits = state->bits; \
442 /* Restore state from registers in inflate() */
449 state->hold = hold; \
450 state->bits = bits; \
502 inflate() uses a state machine to process as much input data and generate as
503 much output data as possible before returning. The state machine is
506 for (;;) switch (state) {
512 state = STATEm;
519 next state. The NEEDBITS() macro is usually the way the state evaluates
542 state information is maintained to continue the loop where it left off
544 would all have to actually be part of the saved state in case NEEDBITS()
553 state = STATEx;
556 As shown above, if the next state is also the next case, then the break
559 A state may also return if there is not enough output space available to
560 complete that state. Those states are copying stored data, writing a
587 struct inflate_state FAR *state;
606 if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
610 state = (struct inflate_state FAR *)strm->state;
611 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
617 switch (state->mode) {
619 if (state->wrap == 0) {
620 state->mode = TYPEDO;
625 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
626 state->check = z_crc32(0L, Z_NULL, 0);
627 CRC2(state->check, hold);
629 state->mode = FLAGS;
632 state->flags = 0; /* expect zlib header */
633 if (state->head != Z_NULL)
634 state->head->done = -1;
635 if (!(state->wrap & 1) || /* check if zlib header allowed */
641 state->mode = BAD;
646 state->mode = BAD;
651 if (len > state->wbits) {
653 state->mode = BAD;
656 state->dmax = 1U << len;
658 strm->adler = state->check = adler32(0L, Z_NULL, 0);
659 state->mode = hold & 0x200 ? DICTID : TYPE;
665 state->flags = (int)(hold);
666 if ((state->flags & 0xff) != Z_DEFLATED) {
668 state->mode = BAD;
671 if (state->flags & 0xe000) {
673 state->mode = BAD;
676 if (state->head != Z_NULL)
677 state->head->text = (int)((hold >> 8) & 1);
678 if (state->flags & 0x0200) CRC2(state->check, hold);
680 state->mode = TIME;
683 if (state->head != Z_NULL)
684 state->head->time = hold;
685 if (state->flags & 0x0200) CRC4(state->check, hold);
687 state->mode = OS;
690 if (state->head != Z_NULL) {
691 state->head->xflags = (int)(hold & 0xff);
692 state->head->os = (int)(hold >> 8);
694 if (state->flags & 0x0200) CRC2(state->check, hold);
696 state->mode = EXLEN;
698 if (state->flags & 0x0400) {
700 state->length = (unsigned)(hold);
701 if (state->head != Z_NULL)
702 state->head->extra_len = (unsigned)hold;
703 if (state->flags & 0x0200) CRC2(state->check, hold);
706 else if (state->head != Z_NULL)
707 state->head->extra = Z_NULL;
708 state->mode = EXTRA;
710 if (state->flags & 0x0400) {
711 copy = state->length;
714 if (state->head != Z_NULL &&
715 state->head->extra != Z_NULL) {
716 len = state->head->extra_len - state->length;
717 zmemcpy(state->head->extra + len, next,
718 len + copy > state->head->extra_max ?
719 state->head->extra_max - len : copy);
721 if (state->flags & 0x0200)
722 state->check = z_crc32(state->check, next, copy);
725 state->length -= copy;
727 if (state->length) goto inf_leave;
729 state->length = 0;
730 state->mode = NAME;
732 if (state->flags & 0x0800) {
737 if (state->head != Z_NULL &&
738 state->head->name != Z_NULL &&
739 state->length < state->head->name_max)
740 state->head->name[state->length++] = len;
742 if (state->flags & 0x0200)
743 state->check = z_crc32(state->check, next, copy);
748 else if (state->head != Z_NULL)
749 state->head->name = Z_NULL;
750 state->length = 0;
751 state->mode = COMMENT;
753 if (state->flags & 0x1000) {
758 if (state->head != Z_NULL &&
759 state->head->comment != Z_NULL &&
760 state->length < state->head->comm_max)
761 state->head->comment[state->length++] = len;
763 if (state->flags & 0x0200)
764 state->check = z_crc32(state->check, next, copy);
769 else if (state->head != Z_NULL)
770 state->head->comment = Z_NULL;
771 state->mode = HCRC;
773 if (state->flags & 0x0200) {
775 if (hold != (state->check & 0xffff)) {
777 state->mode = BAD;
782 if (state->head != Z_NULL) {
783 state->head->hcrc = (int)((state->flags >> 9) & 1);
784 state->head->done = 1;
786 strm->adler = state->check = z_crc32(0L, Z_NULL, 0);
787 state->mode = TYPE;
792 strm->adler = state->check = REVERSE(hold);
794 state->mode = DICT;
796 if (state->havedict == 0) {
800 strm->adler = state->check = adler32(0L, Z_NULL, 0);
801 state->mode = TYPE;
805 if (state->last) {
807 state->mode = CHECK;
811 state->last = BITS(1);
816 state->last ? " (last)" : ""));
817 state->mode = STORED;
820 fixedtables(state);
822 state->last ? " (last)" : ""));
823 state->mode = LEN; /* decode codes */
827 state->last ? " (last)" : ""));
828 state->mode = TABLE;
832 state->mode = BAD;
841 state->mode = BAD;
844 state->length = (unsigned)hold & 0xffff;
846 state->length));
848 state->mode = COPY;
850 copy = state->length;
860 state->length -= copy;
864 state->mode = TYPE;
868 state->nlen = BITS(5) + 257;
870 state->ndist = BITS(5) + 1;
872 state->ncode = BITS(4) + 4;
875 if (state->nlen > 286 || state->ndist > 30) {
877 state->mode = BAD;
882 state->have = 0;
883 state->mode = LENLENS;
885 while (state->have < state->ncode) {
887 state->lens[order[state->have++]] = (unsigned short)BITS(3);
890 while (state->have < 19)
891 state->lens[order[state->have++]] = 0;
892 state->next = state->codes;
893 state->lencode = (code const FAR *)(state->next);
894 state->lenbits = 7;
895 ret = inflate_table(CODES, state->lens, 19, &(state->next),
896 &(state->lenbits), state->work);
899 state->mode = BAD;
903 state->have = 0;
904 state->mode = CODELENS;
906 while (state->have < state->nlen + state->ndist) {
908 this = state->lencode[BITS(state->lenbits)];
915 state->lens[state->have++] = this.val;
921 if (state->have == 0) {
923 state->mode = BAD;
926 len = state->lens[state->have - 1];
944 if (state->have + copy > state->nlen + state->ndist) {
946 state->mode = BAD;
950 state->lens[state->have++] = (unsigned short)len;
955 if (state->mode == BAD) break;
958 state->next = state->codes;
959 state->lencode = (code const FAR *)(state->next);
960 state->lenbits = 9;
961 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
962 &(state->lenbits), state->work);
965 state->mode = BAD;
968 state->distcode = (code const FAR *)(state->next);
969 state->distbits = 6;
970 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
971 &(state->next), &(state->distbits), state->work);
974 state->mode = BAD;
978 state->mode = LEN;
987 this = state->lencode[BITS(state->lenbits)];
994 this = state->lencode[last.val +
1002 state->length = (unsigned)this.val;
1007 state->mode = LIT;
1012 state->mode = TYPE;
1017 state->mode = BAD;
1020 state->extra = (unsigned)(this.op) & 15;
1021 state->mode = LENEXT;
1023 if (state->extra) {
1024 NEEDBITS(state->extra);
1025 state->length += BITS(state->extra);
1026 DROPBITS(state->extra);
1028 Tracevv((stderr, "inflate: length %u\n", state->length));
1029 state->mode = DIST;
1032 this = state->distcode[BITS(state->distbits)];
1039 this = state->distcode[last.val +
1049 state->mode = BAD;
1052 state->offset = (unsigned)this.val;
1053 state->extra = (unsigned)(this.op) & 15;
1054 state->mode = DISTEXT;
1056 if (state->extra) {
1057 NEEDBITS(state->extra);
1058 state->offset += BITS(state->extra);
1059 DROPBITS(state->extra);
1062 if (state->offset > state->dmax) {
1064 state->mode = BAD;
1068 if (state->offset > state->whave + out - left) {
1070 state->mode = BAD;
1073 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1074 state->mode = MATCH;
1078 if (state->offset > copy) { /* copy from window */
1079 copy = state->offset - copy;
1080 if (copy > state->write) {
1081 copy -= state->write;
1082 from = state->window + (state->wsize - copy);
1085 from = state->window + (state->write - copy);
1086 if (copy > state->length) copy = state->length;
1089 from = put - state->offset;
1090 copy = state->length;
1094 state->length -= copy;
1098 if (state->length == 0) state->mode = LEN;
1102 *put++ = (unsigned char)(state->length);
1104 state->mode = LEN;
1107 if (state->wrap) {
1111 state->total += out;
1113 strm->adler = state->check =
1114 UPDATE(state->check, put - out, out);
1118 state->flags ? hold :
1120 REVERSE(hold)) != state->check) {
1122 state->mode = BAD;
1129 state->mode = LENGTH;
1131 if (state->wrap && state->flags) {
1133 if (hold != (state->total & 0xffffffffUL)) {
1135 state->mode = BAD;
1142 state->mode = DONE;
1159 error. Call updatewindow() to create and/or update the window state.
1164 if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
1166 state->mode = MEM;
1173 state->total += out;
1174 if (state->wrap && out)
1175 strm->adler = state->check =
1176 UPDATE(state->check, strm->next_out - out, out);
1177 strm->data_type = state->bits + (state->last ? 64 : 0) +
1178 (state->mode == TYPE ? 128 : 0);
1187 struct inflate_state FAR *state;
1188 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
1190 state = (struct inflate_state FAR *)strm->state;
1191 if (state->window != Z_NULL) ZFREE(strm, state->window);
1192 ZFREE(strm, strm->state);
1193 strm->state = Z_NULL;
1203 struct inflate_state FAR *state;
1206 /* check state */
1207 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1208 state = (struct inflate_state FAR *)strm->state;
1209 if (state->wrap != 0 && state->mode != DICT)
1213 if (state->mode == DICT) {
1216 if (id != state->check)
1222 state->mode = MEM;
1225 if (dictLength > state->wsize) {
1226 zmemcpy(state->window, dictionary + dictLength - state->wsize,
1227 state->wsize);
1228 state->whave = state->wsize;
1231 zmemcpy(state->window + state->wsize - dictLength, dictionary,
1233 state->whave = dictLength;
1235 state->havedict = 1;
1244 struct inflate_state FAR *state;
1246 /* check state */
1247 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1248 state = (struct inflate_state FAR *)strm->state;
1249 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1252 state->head = head;
1261 state. If on return *have equals four, then the pattern was found and the
1265 called again with more data and the *have state. *have is initialized to
1297 struct inflate_state FAR *state;
1300 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1301 state = (struct inflate_state FAR *)strm->state;
1302 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1305 if (state->mode != SYNC) {
1306 state->mode = SYNC;
1307 state->hold <<= state->bits & 7;
1308 state->bits -= state->bits & 7;
1310 while (state->bits >= 8) {
1311 buf[len++] = (unsigned char)(state->hold);
1312 state->hold >>= 8;
1313 state->bits -= 8;
1315 state->have = 0;
1316 syncsearch(&(state->have), buf, len);
1320 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1326 if (state->have != 4) return Z_DATA_ERROR;
1330 state->mode = TYPE;
1345 struct inflate_state FAR *state;
1347 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1348 state = (struct inflate_state FAR *)strm->state;
1349 return state->mode == STORED && state->bits == 0;
1356 struct inflate_state FAR *state;
1362 if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
1365 state = (struct inflate_state FAR *)source->state;
1372 if (state->window != Z_NULL) {
1374 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1381 /* copy state */
1383 zmemcpy(copy, state, sizeof(struct inflate_state));
1384 if (state->lencode >= state->codes &&
1385 state->lencode <= state->codes + ENOUGH - 1) {
1386 copy->lencode = copy->codes + (state->lencode - state->codes);
1387 copy->distcode = copy->codes + (state->distcode - state->codes);
1389 copy->next = copy->codes + (state->next - state->codes);
1391 wsize = 1U << state->wbits;
1392 zmemcpy(window, state->window, wsize);
1395 dest->state = (struct internal_state FAR *)copy;