Lines Matching refs:state

97 local void fixedtables OF((struct inflate_state FAR *state));
109 struct inflate_state FAR *state; local
113 state = (struct inflate_state FAR *)strm->state;
114 if (state == Z_NULL || state->strm != strm ||
115 state->mode < HEAD || state->mode > SYNC)
123 struct inflate_state FAR *state; local
126 state = (struct inflate_state FAR *)strm->state;
127 strm->total_in = strm->total_out = state->total = 0;
129 if (state->wrap) /* to support ill-conceived Java test suite */
130 strm->adler = state->wrap & 1;
131 state->mode = HEAD;
132 state->last = 0;
133 state->havedict = 0;
134 state->flags = -1;
135 state->dmax = 32768U;
136 state->head = Z_NULL;
137 state->hold = 0;
138 state->bits = 0;
139 state->lencode = state->distcode = state->next = state->codes;
140 state->sane = 1;
141 state->back = -1;
149 struct inflate_state FAR *state; local
152 state = (struct inflate_state FAR *)strm->state;
153 state->wsize = 0;
154 state->whave = 0;
155 state->wnext = 0;
164 struct inflate_state FAR *state; local
168 state = (struct inflate_state FAR *)strm->state;
186 if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
187 ZFREE(strm, state->window);
188 state->window = Z_NULL;
192 state->wrap = wrap;
193 state->wbits = (unsigned)windowBits;
204 struct inflate_state FAR *state; local
225 state = (struct inflate_state FAR *)
227 if (state == Z_NULL) return Z_MEM_ERROR;
229 strm->state = (struct internal_state FAR *)state;
230 state->strm = strm;
231 state->window = Z_NULL;
232 state->mode = HEAD; /* to pass state test in inflateReset2() */
235 ZFREE(strm, state);
236 strm->state = Z_NULL;
254 struct inflate_state FAR *state; local
257 state = (struct inflate_state FAR *)strm->state;
259 state->hold = 0;
260 state->bits = 0;
263 if (bits > 16 || state->bits + (uInt)bits > 32) return Z_STREAM_ERROR;
265 state->hold += (unsigned)value << state->bits;
266 state->bits += (uInt)bits;
280 local void fixedtables(state) in fixedtables() argument
281 struct inflate_state FAR *state; in fixedtables()
295 while (sym < 144) state->lens[sym++] = 8;
296 while (sym < 256) state->lens[sym++] = 9;
297 while (sym < 280) state->lens[sym++] = 7;
298 while (sym < 288) state->lens[sym++] = 8;
302 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
306 while (sym < 32) state->lens[sym++] = 5;
309 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
317 state->lencode = lenfix;
318 state->lenbits = 9;
319 state->distcode = distfix;
320 state->distbits = 5;
347 struct inflate_state state; in makefixed() local
349 fixedtables(&state); in makefixed()
364 printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op, in makefixed()
365 state.lencode[low].bits, state.lencode[low].val); in makefixed()
375 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, in makefixed()
376 state.distcode[low].val); in makefixed()
403 struct inflate_state FAR *state; local
406 state = (struct inflate_state FAR *)strm->state;
409 if (state->window == Z_NULL) {
410 state->window = (unsigned char FAR *)
411 ZALLOC(strm, 1U << state->wbits,
413 if (state->window == Z_NULL) return 1;
417 if (state->wsize == 0) {
418 state->wsize = 1U << state->wbits;
419 state->wnext = 0;
420 state->whave = 0;
424 if (copy >= state->wsize) {
425 zmemcpy(state->window, end - state->wsize, state->wsize);
426 state->wnext = 0;
427 state->whave = state->wsize;
430 dist = state->wsize - state->wnext;
432 zmemcpy(state->window + state->wnext, end - copy, dist);
435 zmemcpy(state->window, end - copy, copy);
436 state->wnext = copy;
437 state->whave = state->wsize;
440 state->wnext += dist;
441 if (state->wnext == state->wsize) state->wnext = 0;
442 if (state->whave < state->wsize) state->whave += dist;
453 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
484 hold = state->hold; \
485 bits = state->bits; \
495 state->hold = hold; \
496 state->bits = bits; \
628 struct inflate_state FAR *state; local
651 state = (struct inflate_state FAR *)strm->state;
652 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
658 switch (state->mode) {
660 if (state->wrap == 0) {
661 state->mode = TYPEDO;
666 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
667 if (state->wbits == 0)
668 state->wbits = 15;
669 state->check = crc32(0L, Z_NULL, 0);
670 CRC2(state->check, hold);
672 state->mode = FLAGS;
675 if (state->head != Z_NULL)
676 state->head->done = -1;
677 if (!(state->wrap & 1) || /* check if zlib header allowed */
683 state->mode = BAD;
688 state->mode = BAD;
693 if (state->wbits == 0)
694 state->wbits = len;
695 if (len > 15 || len > state->wbits) {
697 state->mode = BAD;
700 state->dmax = 1U << len;
701 state->flags = 0; /* indicate zlib header */
703 strm->adler = state->check = adler32(0L, Z_NULL, 0);
704 state->mode = hold & 0x200 ? DICTID : TYPE;
710 state->flags = (int)(hold);
711 if ((state->flags & 0xff) != Z_DEFLATED) {
713 state->mode = BAD;
716 if (state->flags & 0xe000) {
718 state->mode = BAD;
721 if (state->head != Z_NULL)
722 state->head->text = (int)((hold >> 8) & 1);
723 if ((state->flags & 0x0200) && (state->wrap & 4))
724 CRC2(state->check, hold);
726 state->mode = TIME;
730 if (state->head != Z_NULL)
731 state->head->time = hold;
732 if ((state->flags & 0x0200) && (state->wrap & 4))
733 CRC4(state->check, hold);
735 state->mode = OS;
739 if (state->head != Z_NULL) {
740 state->head->xflags = (int)(hold & 0xff);
741 state->head->os = (int)(hold >> 8);
743 if ((state->flags & 0x0200) && (state->wrap & 4))
744 CRC2(state->check, hold);
746 state->mode = EXLEN;
749 if (state->flags & 0x0400) {
751 state->length = (unsigned)(hold);
752 if (state->head != Z_NULL)
753 state->head->extra_len = (unsigned)hold;
754 if ((state->flags & 0x0200) && (state->wrap & 4))
755 CRC2(state->check, hold);
758 else if (state->head != Z_NULL)
759 state->head->extra = Z_NULL;
760 state->mode = EXTRA;
763 if (state->flags & 0x0400) {
764 copy = state->length;
767 if (state->head != Z_NULL &&
768 state->head->extra != Z_NULL) {
769 len = state->head->extra_len - state->length;
770 zmemcpy(state->head->extra + len, next,
771 len + copy > state->head->extra_max ?
772 state->head->extra_max - len : copy);
774 if ((state->flags & 0x0200) && (state->wrap & 4))
775 state->check = crc32(state->check, next, copy);
778 state->length -= copy;
780 if (state->length) goto inf_leave;
782 state->length = 0;
783 state->mode = NAME;
786 if (state->flags & 0x0800) {
791 if (state->head != Z_NULL &&
792 state->head->name != Z_NULL &&
793 state->length < state->head->name_max)
794 state->head->name[state->length++] = (Bytef)len;
796 if ((state->flags & 0x0200) && (state->wrap & 4))
797 state->check = crc32(state->check, next, copy);
802 else if (state->head != Z_NULL)
803 state->head->name = Z_NULL;
804 state->length = 0;
805 state->mode = COMMENT;
808 if (state->flags & 0x1000) {
813 if (state->head != Z_NULL &&
814 state->head->comment != Z_NULL &&
815 state->length < state->head->comm_max)
816 state->head->comment[state->length++] = (Bytef)len;
818 if ((state->flags & 0x0200) && (state->wrap & 4))
819 state->check = crc32(state->check, next, copy);
824 else if (state->head != Z_NULL)
825 state->head->comment = Z_NULL;
826 state->mode = HCRC;
829 if (state->flags & 0x0200) {
831 if ((state->wrap & 4) && hold != (state->check & 0xffff)) {
833 state->mode = BAD;
838 if (state->head != Z_NULL) {
839 state->head->hcrc = (int)((state->flags >> 9) & 1);
840 state->head->done = 1;
842 strm->adler = state->check = crc32(0L, Z_NULL, 0);
843 state->mode = TYPE;
848 strm->adler = state->check = ZSWAP32(hold);
850 state->mode = DICT;
853 if (state->havedict == 0) {
857 strm->adler = state->check = adler32(0L, Z_NULL, 0);
858 state->mode = TYPE;
864 if (state->last) {
866 state->mode = CHECK;
870 state->last = BITS(1);
875 state->last ? " (last)" : ""));
876 state->mode = STORED;
879 fixedtables(state);
881 state->last ? " (last)" : ""));
882 state->mode = LEN_; /* decode codes */
890 state->last ? " (last)" : ""));
891 state->mode = TABLE;
895 state->mode = BAD;
904 state->mode = BAD;
907 state->length = (unsigned)hold & 0xffff;
909 state->length));
911 state->mode = COPY_;
915 state->mode = COPY;
918 copy = state->length;
928 state->length -= copy;
932 state->mode = TYPE;
936 state->nlen = BITS(5) + 257;
938 state->ndist = BITS(5) + 1;
940 state->ncode = BITS(4) + 4;
943 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 = (const code FAR *)(state->next);
963 state->lenbits = 7;
964 ret = inflate_table(CODES, state->lens, 19, &(state->next),
965 &(state->lenbits), state->work);
968 state->mode = BAD;
972 state->have = 0;
973 state->mode = CODELENS;
976 while (state->have < state->nlen + state->ndist) {
978 here = state->lencode[BITS(state->lenbits)];
984 state->lens[state->have++] = here.val;
990 if (state->have == 0) {
992 state->mode = BAD;
995 len = state->lens[state->have - 1];
1013 if (state->have + copy > state->nlen + state->ndist) {
1015 state->mode = BAD;
1019 state->lens[state->have++] = (unsigned short)len;
1024 if (state->mode == BAD) break;
1027 if (state->lens[256] == 0) {
1029 state->mode = BAD;
1036 state->next = state->codes;
1037 state->lencode = (const code FAR *)(state->next);
1038 state->lenbits = 9;
1039 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1040 &(state->lenbits), state->work);
1043 state->mode = BAD;
1046 state->distcode = (const code FAR *)(state->next);
1047 state->distbits = 6;
1048 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
1049 &(state->next), &(state->distbits), state->work);
1052 state->mode = BAD;
1056 state->mode = LEN_;
1060 state->mode = LEN;
1067 if (state->mode == TYPE)
1068 state->back = -1;
1071 state->back = 0;
1073 here = state->lencode[BITS(state->lenbits)];
1080 here = state->lencode[last.val +
1086 state->back += last.bits;
1089 state->back += here.bits;
1090 state->length = (unsigned)here.val;
1095 state->mode = LIT;
1100 state->back = -1;
1101 state->mode = TYPE;
1106 state->mode = BAD;
1109 state->extra = (unsigned)(here.op) & 15;
1110 state->mode = LENEXT;
1113 if (state->extra) {
1114 NEEDBITS(state->extra);
1115 state->length += BITS(state->extra);
1116 DROPBITS(state->extra);
1117 state->back += state->extra;
1119 Tracevv((stderr, "inflate: length %u\n", state->length));
1120 state->was = state->length;
1121 state->mode = DIST;
1125 here = state->distcode[BITS(state->distbits)];
1132 here = state->distcode[last.val +
1138 state->back += last.bits;
1141 state->back += here.bits;
1144 state->mode = BAD;
1147 state->offset = (unsigned)here.val;
1148 state->extra = (unsigned)(here.op) & 15;
1149 state->mode = DISTEXT;
1152 if (state->extra) {
1153 NEEDBITS(state->extra);
1154 state->offset += BITS(state->extra);
1155 DROPBITS(state->extra);
1156 state->back += state->extra;
1159 if (state->offset > state->dmax) {
1161 state->mode = BAD;
1165 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1166 state->mode = MATCH;
1171 if (state->offset > copy) { /* copy from window */
1172 copy = state->offset - copy;
1173 if (copy > state->whave) {
1174 if (state->sane) {
1176 state->mode = BAD;
1181 copy -= state->whave;
1182 if (copy > state->length) copy = state->length;
1185 state->length -= copy;
1189 if (state->length == 0) state->mode = LEN;
1193 if (copy > state->wnext) {
1194 copy -= state->wnext;
1195 from = state->window + (state->wsize - copy);
1198 from = state->window + (state->wnext - copy);
1199 if (copy > state->length) copy = state->length;
1202 from = put - state->offset;
1203 copy = state->length;
1207 state->length -= copy;
1211 if (state->length == 0) state->mode = LEN;
1215 *put++ = (unsigned char)(state->length);
1217 state->mode = LEN;
1220 if (state->wrap) {
1224 state->total += out;
1225 if ((state->wrap & 4) && out)
1226 strm->adler = state->check =
1227 UPDATE_CHECK(state->check, put - out, out);
1229 if ((state->wrap & 4) && (
1231 state->flags ? hold :
1233 ZSWAP32(hold)) != state->check) {
1235 state->mode = BAD;
1242 state->mode = LENGTH;
1245 if (state->wrap && state->flags) {
1247 if ((state->wrap & 4) && hold != (state->total & 0xffffffff)) {
1249 state->mode = BAD;
1256 state->mode = DONE;
1280 if (state->wsize || (out != strm->avail_out && state->mode < BAD &&
1281 (state->mode < CHECK || flush != Z_FINISH)))
1283 state->mode = MEM;
1290 state->total += out;
1291 if ((state->wrap & 4) && out)
1292 strm->adler = state->check =
1293 UPDATE_CHECK(state->check, strm->next_out - out, out);
1294 strm->data_type = (int)state->bits + (state->last ? 64 : 0) +
1295 (state->mode == TYPE ? 128 : 0) +
1296 (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0);
1305 struct inflate_state FAR *state; local
1308 state = (struct inflate_state FAR *)strm->state;
1309 if (state->window != Z_NULL) ZFREE(strm, state->window);
1310 ZFREE(strm, strm->state);
1311 strm->state = Z_NULL;
1321 struct inflate_state FAR *state; local
1325 state = (struct inflate_state FAR *)strm->state;
1328 if (state->whave && dictionary != Z_NULL) {
1329 zmemcpy(dictionary, state->window + state->wnext,
1330 state->whave - state->wnext);
1331 zmemcpy(dictionary + state->whave - state->wnext,
1332 state->window, state->wnext);
1335 *dictLength = state->whave;
1344 struct inflate_state FAR *state; local
1350 state = (struct inflate_state FAR *)strm->state;
1351 if (state->wrap != 0 && state->mode != DICT)
1355 if (state->mode == DICT) {
1358 if (dictid != state->check)
1366 state->mode = MEM;
1369 state->havedict = 1;
1378 struct inflate_state FAR *state; local
1382 state = (struct inflate_state FAR *)strm->state;
1383 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1386 state->head = head;
1432 struct inflate_state FAR *state; local
1436 state = (struct inflate_state FAR *)strm->state;
1437 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1440 if (state->mode != SYNC) {
1441 state->mode = SYNC;
1442 state->hold <<= state->bits & 7;
1443 state->bits -= state->bits & 7;
1445 while (state->bits >= 8) {
1446 buf[len++] = (unsigned char)(state->hold);
1447 state->hold >>= 8;
1448 state->bits -= 8;
1450 state->have = 0;
1451 syncsearch(&(state->have), buf, len);
1455 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1461 if (state->have != 4) return Z_DATA_ERROR;
1462 if (state->flags == -1)
1463 state->wrap = 0; /* if no header yet, treat as raw */
1465 state->wrap &= ~4; /* no point in computing a check value now */
1466 flags = state->flags;
1470 state->flags = flags;
1471 state->mode = TYPE;
1486 struct inflate_state FAR *state; local
1489 state = (struct inflate_state FAR *)strm->state;
1490 return state->mode == STORED && state->bits == 0;
1497 struct inflate_state FAR *state; local
1505 state = (struct inflate_state FAR *)source->state;
1512 if (state->window != Z_NULL) {
1514 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1523 zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state));
1525 if (state->lencode >= state->codes &&
1526 state->lencode <= state->codes + ENOUGH - 1) {
1527 copy->lencode = copy->codes + (state->lencode - state->codes);
1528 copy->distcode = copy->codes + (state->distcode - state->codes);
1530 copy->next = copy->codes + (state->next - state->codes);
1532 wsize = 1U << state->wbits;
1533 zmemcpy(window, state->window, wsize);
1536 dest->state = (struct internal_state FAR *)copy;
1544 struct inflate_state FAR *state; local
1547 state = (struct inflate_state FAR *)strm->state;
1549 state->sane = !subvert;
1553 state->sane = 1;
1562 struct inflate_state FAR *state; local
1565 state = (struct inflate_state FAR *)strm->state;
1566 if (check && state->wrap)
1567 state->wrap |= 4;
1569 state->wrap &= ~4;
1576 struct inflate_state FAR *state; local
1580 state = (struct inflate_state FAR *)strm->state;
1581 return (long)(((unsigned long)((long)state->back)) << 16) +
1582 (state->mode == COPY ? state->length :
1583 (state->mode == MATCH ? state->was - state->length : 0));
1589 struct inflate_state FAR *state; local
1591 state = (struct inflate_state FAR *)strm->state;
1592 return (unsigned long)(state->next - state->codes);