98 void makefixed
OF((
void));
109 strm->total_in = strm->total_out = state->
total = 0;
112 strm->adler = state->
wrap & 1;
116 state->
dmax = 32768U;
123 Tracev((stderr,
"inflate: reset\n"));
149 if (windowBits < 0) {
151 windowBits = -windowBits;
154 wrap = (windowBits >> 4) + 1;
162 if (windowBits && (windowBits < 8 || windowBits > 15))
171 state->
wbits = (unsigned)windowBits;
181 stream_size != (
int)(
sizeof(
z_stream)))
185 if (strm->zalloc == (alloc_func)0) {
190 strm->opaque = (voidpf)0;
193 if (strm->zfree == (free_func)0)
202 Tracev((stderr,
"inflate: allocated\n"));
230 value &= (1L <<
bits) - 1;
231 state->
hold += value << state->
bits;
249 static int virgin = 1;
250 static code *lenfix, *distfix;
251 static code fixed[544];
260 while (sym < 144) state->lens[sym++] = 8;
261 while (sym < 256) state->lens[sym++] = 9;
262 while (sym < 280) state->lens[sym++] = 7;
263 while (sym < 288) state->lens[sym++] = 8;
271 while (sym < 32) state->lens[sym++] = 5;
282 state->lencode = lenfix;
284 state->distcode = distfix;
315 puts(
" /* inffixed.h -- table for decoding fixed codes");
316 puts(
" * Generated automatically by makefixed().");
319 puts(
" /* WARNING: this file should *not* be used by applications.");
320 puts(
" It is part of the implementation of this library and is");
321 puts(
" subject to change. Applications should only use zlib.h.");
325 printf(
" static const code lenfix[%u] = {", size);
328 if ((low % 7) == 0)
printf(
"\n ");
329 printf(
"{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
330 state.lencode[low].bits, state.lencode[low].val);
331 if (++low == size)
break;
336 printf(
"\n static const code distfix[%u] = {", size);
339 if ((low % 6) == 0)
printf(
"\n ");
340 printf(
"{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
341 state.distcode[low].val);
342 if (++low == size)
break;
372 state->
window = (
unsigned char FAR *)
374 sizeof(
unsigned char));
379 if (state->
wsize == 0) {
386 copy = out - strm->avail_out;
387 if (copy >= state->
wsize) {
394 if (dist > copy) dist =
copy;
403 state->
wnext += dist;
415 # define UPDATE(check, buf, len) \
416 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
418 # define UPDATE(check, buf, len) adler32(check, buf, len)
423 # define CRC2(check, word) \
425 hbuf[0] = (unsigned char)(word); \
426 hbuf[1] = (unsigned char)((word) >> 8); \
427 check = crc32(check, hbuf, 2); \
430 # define CRC4(check, word) \
432 hbuf[0] = (unsigned char)(word); \
433 hbuf[1] = (unsigned char)((word) >> 8); \
434 hbuf[2] = (unsigned char)((word) >> 16); \
435 hbuf[3] = (unsigned char)((word) >> 24); \
436 check = crc32(check, hbuf, 4); \
443 put = strm->next_out; \
444 left = strm->avail_out; \
445 next = strm->next_in; \
446 have = strm->avail_in; \
447 hold = state->hold; \
448 bits = state->bits; \
454 strm->next_out = put; \
455 strm->avail_out = left; \
456 strm->next_in = next; \
457 strm->avail_in = have; \
458 state->hold = hold; \
459 state->bits = bits; \
473 if (have == 0) goto inf_leave; \
475 hold += (unsigned long)(*next++) << bits; \
481 #define NEEDBITS(n) \
483 while (bits < (unsigned)(n)) \
489 ((unsigned)hold & ((1U << (n)) - 1))
492 #define DROPBITS(n) \
495 bits -= (unsigned)(n); \
590 unsigned char FAR *
next;
591 unsigned char FAR *put;
597 unsigned char FAR *from;
603 unsigned char hbuf[4];
605 static const unsigned short order[19] =
606 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
609 (strm->next_in ==
Z_NULL && strm->avail_in != 0))
619 switch (state->
mode) {
621 if (state->
wrap == 0) {
627 if ((state->
wrap & 2) && hold == 0x8b1f) {
636 state->
head->done = -1;
637 if (!(state->
wrap & 1) ||
641 ((
BITS(8) << 8) + (hold >> 8)) % 31) {
642 strm->msg = (
char *)
"incorrect header check";
647 strm->msg = (
char *)
"unknown compression method";
653 if (state->
wbits == 0)
655 else if (len > state->
wbits) {
656 strm->msg = (
char *)
"invalid window size";
661 Tracev((stderr,
"inflate: zlib header ok\n"));
671 strm->msg = (
char *)
"unknown compression method";
675 if (state->
flags & 0xe000) {
676 strm->msg = (
char *)
"unknown header flags set";
681 state->
head->text = (
int)((hold >> 8) & 1);
695 state->
head->xflags = (
int)(hold & 0xff);
696 state->
head->os = (
int)(hold >> 8);
702 if (state->
flags & 0x0400) {
704 state->
length = (unsigned)(hold);
706 state->
head->extra_len = (unsigned)hold;
714 if (state->
flags & 0x0400) {
716 if (copy > have) copy =
have;
722 len + copy > state->
head->extra_max ?
723 state->
head->extra_max - len : copy);
725 if (state->
flags & 0x0200)
731 if (state->
length)
goto inf_leave;
736 if (state->
flags & 0x0800) {
737 if (have == 0)
goto inf_leave;
740 len = (unsigned)(next[copy++]);
745 }
while (len && copy < have);
746 if (state->
flags & 0x0200)
750 if (len)
goto inf_leave;
757 if (state->
flags & 0x1000) {
758 if (have == 0)
goto inf_leave;
761 len = (unsigned)(next[copy++]);
766 }
while (len && copy < have);
767 if (state->
flags & 0x0200)
771 if (len)
goto inf_leave;
777 if (state->
flags & 0x0200) {
779 if (hold != (state->
check & 0xffff)) {
780 strm->msg = (
char *)
"header crc mismatch";
788 state->
head->done = 1;
819 Tracev((stderr,
"inflate: stored block%s\n",
820 state->
last ?
" (last)" :
""));
825 Tracev((stderr,
"inflate: fixed codes block%s\n",
826 state->
last ?
" (last)" :
""));
834 Tracev((stderr,
"inflate: dynamic codes block%s\n",
835 state->
last ?
" (last)" :
""));
839 strm->msg = (
char *)
"invalid block type";
847 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
848 strm->msg = (
char *)
"invalid stored block lengths";
852 state->
length = (unsigned)hold & 0xffff;
853 Tracev((stderr,
"inflate: stored length %u\n",
857 if (flush ==
Z_TREES)
goto inf_leave;
863 if (copy > have) copy =
have;
864 if (copy > left) copy =
left;
865 if (copy == 0)
goto inf_leave;
874 Tracev((stderr,
"inflate: stored end\n"));
885 #ifndef PKZIP_BUG_WORKAROUND
886 if (state->
nlen > 286 || state->
ndist > 30) {
887 strm->msg = (
char *)
"too many length or distance symbols";
892 Tracev((stderr,
"inflate: table sizes ok\n"));
898 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
901 while (state->
have < 19)
902 state->
lens[order[state->
have++]] = 0;
909 strm->msg = (
char *)
"invalid code lengths set";
913 Tracev((stderr,
"inflate: code lengths ok\n"));
920 if ((
unsigned)(here.
bits) <= bits)
break;
928 if (here.
val == 16) {
931 if (state->
have == 0) {
932 strm->msg = (
char *)
"invalid bit length repeat";
940 else if (here.
val == 17) {
955 strm->msg = (
char *)
"invalid bit length repeat";
960 state->
lens[state->
have++] = (
unsigned short)len;
968 if (state->
lens[256] == 0) {
969 strm->msg = (
char *)
"invalid code -- missing end-of-block";
983 strm->msg = (
char *)
"invalid literal/lengths set";
992 strm->msg = (
char *)
"invalid distances set";
996 Tracev((stderr,
"inflate: codes ok\n"));
998 if (flush ==
Z_TREES)
goto inf_leave;
1002 if (have >= 6 && left >= 258) {
1013 if ((
unsigned)(here.
bits) <= bits)
break;
1016 if (here.
op && (here.
op & 0xf0) == 0) {
1021 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1030 if ((
int)(here.
op) == 0) {
1032 "inflate: literal '%c'\n" :
1033 "inflate: literal 0x%02x\n", here.
val));
1038 Tracevv((stderr,
"inflate: end of block\n"));
1044 strm->msg = (
char *)
"invalid literal/length code";
1048 state->
extra = (unsigned)(here.
op) & 15;
1063 if ((
unsigned)(here.
bits) <= bits)
break;
1066 if ((here.
op & 0xf0) == 0) {
1071 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1080 strm->msg = (
char *)
"invalid distance code";
1085 state->
extra = (
unsigned)(here.
op) & 15;
1094 #ifdef INFLATE_STRICT
1096 strm->msg = (
char *)
"invalid distance too far back";
1104 if (left == 0)
goto inf_leave;
1106 if (state->
offset > copy) {
1108 if (copy > state->
whave) {
1110 strm->msg = (
char *)
"invalid distance too far back";
1114 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1115 Trace((stderr,
"inflate.c too far\n"));
1116 copy -= state->
whave;
1118 if (copy > left) copy =
left;
1128 if (copy > state->
wnext) {
1129 copy -= state->
wnext;
1137 from = put - state->
offset;
1140 if (copy > left) copy =
left;
1149 if (left == 0)
goto inf_leave;
1150 *put++ = (
unsigned char)(state->
length);
1158 strm->total_out += out;
1159 state->
total += out;
1161 strm->adler = state->
check =
1166 state->
flags ? hold :
1169 strm->msg = (
char *)
"incorrect data check";
1174 Tracev((stderr,
"inflate: check matches trailer\n"));
1181 if (hold != (state->
total & 0xffffffffUL)) {
1182 strm->msg = (
char *)
"incorrect length check";
1187 Tracev((stderr,
"inflate: length matches trailer\n"));
1212 if (state->
wsize || (out != strm->avail_out && state->
mode <
BAD &&
1218 in -= strm->avail_in;
1219 out -= strm->avail_out;
1220 strm->total_in +=
in;
1221 strm->total_out += out;
1222 state->
total += out;
1223 if (state->
wrap && out)
1224 strm->adler = state->
check =
1226 strm->data_type = state->
bits + (state->
last ? 64 : 0) +
1229 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
1237 if (strm ==
Z_NULL || strm->state ==
Z_NULL || strm->zfree == (free_func)0)
1241 ZFREE(strm, strm->state);
1243 Tracev((stderr,
"inflate: end\n"));
1250 unsigned long dictid;
1251 unsigned char *
next;
1264 dictid =
adler32(dictid, dictionary, dictLength);
1265 if (dictid != state->
check)
1271 next = strm->next_out;
1272 avail = strm->avail_out;
1273 strm->next_out = (Bytef *)dictionary + dictLength;
1274 strm->avail_out = 0;
1276 strm->avail_out = avail;
1277 strm->next_out =
next;
1283 Tracev((stderr,
"inflate: dictionary set\n"));
1320 while (next < len && got < 4) {
1321 if ((
int)(buf[next]) == (got < 2 ? 0 : 0xff))
1336 unsigned long in, out;
1337 unsigned char buf[4];
1351 while (state->
bits >= 8) {
1352 buf[len++] = (
unsigned char)(state->
hold);
1362 strm->avail_in -=
len;
1363 strm->next_in +=
len;
1364 strm->total_in +=
len;
1368 in = strm->total_in; out = strm->total_out;
1370 strm->total_in =
in; strm->total_out = out;
1396 unsigned char FAR *
window;
1401 source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
1411 window = (
unsigned char FAR *)
1412 ZALLOC(source, 1U << state->
wbits,
sizeof(
unsigned char));
1414 ZFREE(source, copy);
1422 if (state->lencode >= state->codes &&
1423 state->lencode <= state->codes +
ENOUGH - 1) {
1424 copy->lencode = copy->codes + (state->lencode - state->codes);
1425 copy->distcode = copy->codes + (state->distcode - state->codes);
1427 copy->next = copy->codes + (state->next - state->codes);
1429 wsize = 1U << state->wbits;
1430 zmemcpy(window, state->window, wsize);
1443 state->
sane = !subvert;
1444 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1456 if (strm ==
Z_NULL || strm->state ==
Z_NULL)
return -1L << 16;
1458 return ((
long)(state->
back) << 16) +
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigned codes, code FAR *FAR *table, unsigned FAR *bits, unsigned short FAR *work)
int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
int ZEXPORT inflateSync(z_streamp strm)
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
int ZEXPORT inflateInit_(z_streamp strm, const char *version, int stream_size)
int ZEXPORT inflateReset2(z_streamp strm, int windowBits)
int ZEXPORT inflateUndermine(z_streamp strm, int subvert)
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
code const FAR * distcode
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
gz_header FAR * gz_headerp
#define CRC2(check, word)
#define ZALLOC(strm, items, size)
void copy(std::vector< T > &main, const std::vector< T > &data)
int ZEXPORT inflateResetKeep(z_streamp strm)
int ZEXPORT inflateSyncPoint(z_streamp strm)
#define ZFREE(strm, addr)
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)
#define UPDATE(check, buf, len)
local unsigned syncsearch(unsigned FAR *have, unsigned char FAR *buf, unsigned len)
local void fixedtables(struct inflate_state FAR *state)
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
#define CRC4(check, word)
unsigned char FAR * window
const XML_Char int const XML_Char * value
int ZEXPORT inflatePrime(z_streamp strm, int bits, int value)
printf("%d Experimental points found\n", nlines)
int ZEXPORT inflateEnd(z_streamp strm)
int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head)
int ZEXPORT inflate(z_streamp strm, int flush)
long ZEXPORT inflateMark(z_streamp strm)
local int updatewindow(z_streamp strm, unsigned out)
void wrap(std::string &str, const size_t lineLength=78, const std::string &separators=" \t")
voidpf alloc_func OF((voidpf opaque, uInt items, uInt size))
int ZEXPORT inflateReset(z_streamp strm)