Lines Matching refs:state

102 local void fixedtables OF((struct inflate_state FAR *state));
113 struct inflate_state FAR *state; local
115 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
116 state = (struct inflate_state FAR *)strm->state;
117 strm->total_in = strm->total_out = state->total = 0;
120 state->mode = HEAD;
121 state->last = 0;
122 state->havedict = 0;
123 state->dmax = 32768U;
124 state->head = Z_NULL;
125 state->wsize = 0;
126 state->whave = 0;
127 state->write = 0;
128 state->hold = 0;
129 state->bits = 0;
130 state->lencode = state->distcode = state->next = state->codes;
140 struct inflate_state FAR *state; local
142 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
143 state = (struct inflate_state FAR *)strm->state;
144 if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
146 state->hold += value << state->bits;
147 state->bits += bits;
157 struct inflate_state FAR *state; local
169 state = (struct inflate_state FAR *)
171 if (state == Z_NULL) return Z_MEM_ERROR;
173 strm->state = (struct internal_state FAR *)state;
175 state->wrap = 0;
179 state->wrap = (windowBits >> 4) + 1;
185 ZFREE(strm, state);
186 strm->state = Z_NULL;
189 state->wbits = (unsigned)windowBits;
190 state->window = Z_NULL;
212 local void fixedtables(state) in fixedtables() argument
213 struct inflate_state FAR *state; in fixedtables()
227 while (sym < 144) state->lens[sym++] = 8;
228 while (sym < 256) state->lens[sym++] = 9;
229 while (sym < 280) state->lens[sym++] = 7;
230 while (sym < 288) state->lens[sym++] = 8;
234 inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
238 while (sym < 32) state->lens[sym++] = 5;
241 inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
249 state->lencode = lenfix;
250 state->lenbits = 9;
251 state->distcode = distfix;
252 state->distbits = 5;
279 struct inflate_state state; in makefixed() local
281 fixedtables(&state); in makefixed()
296 printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits, in makefixed()
297 state.lencode[low].val); in makefixed()
307 printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, in makefixed()
308 state.distcode[low].val); in makefixed()
334 struct inflate_state FAR *state; local
337 state = (struct inflate_state FAR *)strm->state;
340 if (state->window == Z_NULL) {
341 state->window = (unsigned char FAR *)
342 ZALLOC(strm, 1U << state->wbits,
344 if (state->window == Z_NULL) return 1;
348 if (state->wsize == 0) {
349 state->wsize = 1U << state->wbits;
350 state->write = 0;
351 state->whave = 0;
356 if (copy >= state->wsize) {
357 zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
358 state->write = 0;
359 state->whave = state->wsize;
362 dist = state->wsize - state->write;
364 zmemcpy(state->window + state->write, strm->next_out - copy, dist);
367 zmemcpy(state->window, strm->next_out - copy, copy);
368 state->write = copy;
369 state->whave = state->wsize;
372 state->write += dist;
373 if (state->write == state->wsize) state->write = 0;
374 if (state->whave < state->wsize) state->whave += dist;
385 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
416 hold = state->hold; \
417 bits = state->bits; \
427 state->hold = hold; \
428 state->bits = bits; \
565 struct inflate_state FAR *state; local
584 if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
588 state = (struct inflate_state FAR *)strm->state;
589 if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
595 switch (state->mode) {
597 if (state->wrap == 0) {
598 state->mode = TYPEDO;
603 if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
604 state->check = crc32(0L, Z_NULL, 0);
605 CRC2(state->check, hold);
607 state->mode = FLAGS;
610 state->flags = 0; /* expect zlib header */
611 if (state->head != Z_NULL)
612 state->head->done = -1;
613 if (!(state->wrap & 1) || /* check if zlib header allowed */
619 state->mode = BAD;
624 state->mode = BAD;
629 if (len > state->wbits) {
631 state->mode = BAD;
634 state->dmax = 1U << len;
636 strm->adler = state->check = adler32(0L, Z_NULL, 0);
637 state->mode = hold & 0x200 ? DICTID : TYPE;
643 state->flags = (int)(hold);
644 if ((state->flags & 0xff) != Z_DEFLATED) {
646 state->mode = BAD;
649 if (state->flags & 0xe000) {
651 state->mode = BAD;
654 if (state->head != Z_NULL)
655 state->head->text = (int)((hold >> 8) & 1);
656 if (state->flags & 0x0200) CRC2(state->check, hold);
658 state->mode = TIME;
662 if (state->head != Z_NULL)
663 state->head->time = hold;
664 if (state->flags & 0x0200) CRC4(state->check, hold);
666 state->mode = OS;
670 if (state->head != Z_NULL) {
671 state->head->xflags = (int)(hold & 0xff);
672 state->head->os = (int)(hold >> 8);
674 if (state->flags & 0x0200) CRC2(state->check, hold);
676 state->mode = EXLEN;
679 if (state->flags & 0x0400) {
681 state->length = (unsigned)(hold);
682 if (state->head != Z_NULL)
683 state->head->extra_len = (unsigned)hold;
684 if (state->flags & 0x0200) CRC2(state->check, hold);
687 else if (state->head != Z_NULL)
688 state->head->extra = Z_NULL;
689 state->mode = EXTRA;
692 if (state->flags & 0x0400) {
693 copy = state->length;
696 if (state->head != Z_NULL &&
697 state->head->extra != Z_NULL) {
698 len = state->head->extra_len - state->length;
699 zmemcpy(state->head->extra + len, next,
700 len + copy > state->head->extra_max ?
701 state->head->extra_max - len : copy);
703 if (state->flags & 0x0200)
704 state->check = crc32(state->check, next, copy);
707 state->length -= copy;
709 if (state->length) goto inf_leave;
711 state->length = 0;
712 state->mode = NAME;
715 if (state->flags & 0x0800) {
720 if (state->head != Z_NULL &&
721 state->head->name != Z_NULL &&
722 state->length < state->head->name_max)
723 state->head->name[state->length++] = len;
725 if (state->flags & 0x0200)
726 state->check = crc32(state->check, next, copy);
731 else if (state->head != Z_NULL)
732 state->head->name = Z_NULL;
733 state->length = 0;
734 state->mode = COMMENT;
737 if (state->flags & 0x1000) {
742 if (state->head != Z_NULL &&
743 state->head->comment != Z_NULL &&
744 state->length < state->head->comm_max)
745 state->head->comment[state->length++] = len;
747 if (state->flags & 0x0200)
748 state->check = crc32(state->check, next, copy);
753 else if (state->head != Z_NULL)
754 state->head->comment = Z_NULL;
755 state->mode = HCRC;
758 if (state->flags & 0x0200) {
760 if (hold != (state->check & 0xffff)) {
762 state->mode = BAD;
767 if (state->head != Z_NULL) {
768 state->head->hcrc = (int)((state->flags >> 9) & 1);
769 state->head->done = 1;
771 strm->adler = state->check = crc32(0L, Z_NULL, 0);
772 state->mode = TYPE;
777 strm->adler = state->check = REVERSE(hold);
779 state->mode = DICT;
782 if (state->havedict == 0) {
786 strm->adler = state->check = adler32(0L, Z_NULL, 0);
787 state->mode = TYPE;
793 if (state->last) {
795 state->mode = CHECK;
799 state->last = BITS(1);
804 state->last ? " (last)" : ""));
805 state->mode = STORED;
808 fixedtables(state);
810 state->last ? " (last)" : ""));
811 state->mode = LEN; /* decode codes */
815 state->last ? " (last)" : ""));
816 state->mode = TABLE;
820 state->mode = BAD;
829 state->mode = BAD;
832 state->length = (unsigned)hold & 0xffff;
834 state->length));
836 state->mode = COPY;
839 copy = state->length;
849 state->length -= copy;
853 state->mode = TYPE;
857 state->nlen = BITS(5) + 257;
859 state->ndist = BITS(5) + 1;
861 state->ncode = BITS(4) + 4;
864 if (state->nlen > 286 || state->ndist > 30) {
866 state->mode = BAD;
871 state->have = 0;
872 state->mode = LENLENS;
875 while (state->have < state->ncode) {
877 state->lens[order[state->have++]] = (unsigned short)BITS(3);
880 while (state->have < 19)
881 state->lens[order[state->have++]] = 0;
882 state->next = state->codes;
883 state->lencode = (code const FAR *)(state->next);
884 state->lenbits = 7;
885 ret = inflate_table(CODES, state->lens, 19, &(state->next),
886 &(state->lenbits), state->work);
889 state->mode = BAD;
893 state->have = 0;
894 state->mode = CODELENS;
897 while (state->have < state->nlen + state->ndist) {
899 this = state->lencode[BITS(state->lenbits)];
906 state->lens[state->have++] = this.val;
912 if (state->have == 0) {
914 state->mode = BAD;
917 len = state->lens[state->have - 1];
935 if (state->have + copy > state->nlen + state->ndist) {
937 state->mode = BAD;
941 state->lens[state->have++] = (unsigned short)len;
946 if (state->mode == BAD) break;
949 state->next = state->codes;
950 state->lencode = (code const FAR *)(state->next);
951 state->lenbits = 9;
952 ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
953 &(state->lenbits), state->work);
956 state->mode = BAD;
959 state->distcode = (code const FAR *)(state->next);
960 state->distbits = 6;
961 ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
962 &(state->next), &(state->distbits), state->work);
965 state->mode = BAD;
969 state->mode = LEN;
979 this = state->lencode[BITS(state->lenbits)];
986 this = state->lencode[last.val +
994 state->length = (unsigned)this.val;
999 state->mode = LIT;
1004 state->mode = TYPE;
1009 state->mode = BAD;
1012 state->extra = (unsigned)(this.op) & 15;
1013 state->mode = LENEXT;
1016 if (state->extra) {
1017 NEEDBITS(state->extra);
1018 state->length += BITS(state->extra);
1019 DROPBITS(state->extra);
1021 Tracevv((stderr, "inflate: length %u\n", state->length));
1022 state->mode = DIST;
1026 this = state->distcode[BITS(state->distbits)];
1033 this = state->distcode[last.val +
1043 state->mode = BAD;
1046 state->offset = (unsigned)this.val;
1047 state->extra = (unsigned)(this.op) & 15;
1048 state->mode = DISTEXT;
1051 if (state->extra) {
1052 NEEDBITS(state->extra);
1053 state->offset += BITS(state->extra);
1054 DROPBITS(state->extra);
1057 if (state->offset > state->dmax) {
1059 state->mode = BAD;
1063 if (state->offset > state->whave + out - left) {
1065 state->mode = BAD;
1068 Tracevv((stderr, "inflate: distance %u\n", state->offset));
1069 state->mode = MATCH;
1074 if (state->offset > copy) { /* copy from window */
1075 copy = state->offset - copy;
1076 if (copy > state->write) {
1077 copy -= state->write;
1078 from = state->window + (state->wsize - copy);
1081 from = state->window + (state->write - copy);
1082 if (copy > state->length) copy = state->length;
1085 from = put - state->offset;
1086 copy = state->length;
1090 state->length -= copy;
1094 if (state->length == 0) state->mode = LEN;
1098 *put++ = (unsigned char)(state->length);
1100 state->mode = LEN;
1103 if (state->wrap) {
1107 state->total += out;
1109 strm->adler = state->check =
1110 UPDATE(state->check, put - out, out);
1114 state->flags ? hold :
1116 REVERSE(hold)) != state->check) {
1118 state->mode = BAD;
1125 state->mode = LENGTH;
1128 if (state->wrap && state->flags) {
1130 if (hold != (state->total & 0xffffffffUL)) {
1132 state->mode = BAD;
1139 state->mode = DONE;
1162 if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
1164 state->mode = MEM;
1171 state->total += out;
1172 if (state->wrap && out)
1173 strm->adler = state->check =
1174 UPDATE(state->check, strm->next_out - out, out);
1175 strm->data_type = state->bits + (state->last ? 64 : 0) +
1176 (state->mode == TYPE ? 128 : 0);
1185 struct inflate_state FAR *state; local
1186 if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
1188 state = (struct inflate_state FAR *)strm->state;
1189 if (state->window != Z_NULL) ZFREE(strm, state->window);
1190 ZFREE(strm, strm->state);
1191 strm->state = Z_NULL;
1201 struct inflate_state FAR *state; local
1205 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1206 state = (struct inflate_state FAR *)strm->state;
1207 if (state->wrap != 0 && state->mode != DICT)
1211 if (state->mode == DICT) {
1214 if (id != state->check)
1220 state->mode = MEM;
1223 if (dictLength > state->wsize) {
1224 zmemcpy(state->window, dictionary + dictLength - state->wsize,
1225 state->wsize);
1226 state->whave = state->wsize;
1229 zmemcpy(state->window + state->wsize - dictLength, dictionary,
1231 state->whave = dictLength;
1233 state->havedict = 1;
1242 struct inflate_state FAR *state; local
1245 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1246 state = (struct inflate_state FAR *)strm->state;
1247 if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
1250 state->head = head;
1295 struct inflate_state FAR *state; local
1298 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1299 state = (struct inflate_state FAR *)strm->state;
1300 if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
1303 if (state->mode != SYNC) {
1304 state->mode = SYNC;
1305 state->hold <<= state->bits & 7;
1306 state->bits -= state->bits & 7;
1308 while (state->bits >= 8) {
1309 buf[len++] = (unsigned char)(state->hold);
1310 state->hold >>= 8;
1311 state->bits -= 8;
1313 state->have = 0;
1314 (void) syncsearch(&(state->have), buf, len);
1318 len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
1324 if (state->have != 4) return Z_DATA_ERROR;
1328 state->mode = TYPE;
1343 struct inflate_state FAR *state; local
1345 if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
1346 state = (struct inflate_state FAR *)strm->state;
1347 return state->mode == STORED && state->bits == 0;
1354 struct inflate_state FAR *state; local
1360 if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
1363 state = (struct inflate_state FAR *)source->state;
1370 if (state->window != Z_NULL) {
1372 ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
1381 zmemcpy(copy, state, sizeof(struct inflate_state));
1382 if (state->lencode >= state->codes &&
1383 state->lencode <= state->codes + ENOUGH - 1) {
1384 copy->lencode = copy->codes + (state->lencode - state->codes);
1385 copy->distcode = copy->codes + (state->distcode - state->codes);
1387 copy->next = copy->codes + (state->next - state->codes);
1389 wsize = 1U << state->wbits;
1390 zmemcpy(window, state->window, wsize);
1393 dest->state = (struct internal_state FAR *)copy;