105 void makefixed
OF((
void));
116 strm->total_in = strm->total_out = state->
total = 0;
122 state->
dmax = 32768U;
132 Tracev((stderr,
"inflate: reset\n"));
146 if (windowBits < 0) {
148 windowBits = -windowBits;
151 wrap = (windowBits >> 4) + 1;
159 if (windowBits && (windowBits < 8 || windowBits > 15))
168 state->
wbits = (unsigned)windowBits;
178 stream_size != (
int)(
sizeof(
z_stream)))
182 if (strm->zalloc == (alloc_func)0) {
186 if (strm->zfree == (free_func)0) strm->zfree =
zcfree;
190 Tracev((stderr,
"inflate: allocated\n"));
218 value &= (1L <<
bits) - 1;
219 state->
hold += value << state->
bits;
237 static int virgin = 1;
239 static code fixed[544];
248 while (sym < 144) state->lens[sym++] = 8;
249 while (sym < 256) state->lens[sym++] = 9;
250 while (sym < 280) state->lens[sym++] = 7;
251 while (sym < 288) state->lens[sym++] = 8;
259 while (sym < 32) state->lens[sym++] = 5;
303 puts(
" /* inffixed.h -- table for decoding fixed codes");
304 puts(
" * Generated automatically by makefixed().");
307 puts(
" /* WARNING: this file should *not* be used by applications.");
308 puts(
" It is part of the implementation of this library and is");
309 puts(
" subject to change. Applications should only use zlib.h.");
313 printf(
" static const code lenfix[%u] = {", size);
316 if ((low % 7) == 0) printf(
"\n ");
317 printf(
"{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
318 state.lencode[low].val);
319 if (++low == size)
break;
324 printf(
"\n static const code distfix[%u] = {", size);
327 if ((low % 6) == 0) printf(
"\n ");
328 printf(
"{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
329 state.distcode[low].val);
330 if (++low == size)
break;
360 state->
window = (
unsigned char FAR *)
362 sizeof(
unsigned char));
367 if (state->
wsize == 0) {
374 copy = out - strm->avail_out;
375 if (copy >= state->
wsize) {
382 if (dist > copy) dist =
copy;
391 state->
wnext += dist;
403 # define UPDATE(check, buf, len) \
404 (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
406 # define UPDATE(check, buf, len) adler32(check, buf, len)
411 # define CRC2(check, word) \
413 hbuf[0] = (unsigned char)(word); \
414 hbuf[1] = (unsigned char)((word) >> 8); \
415 check = crc32(check, hbuf, 2); \
418 # define CRC4(check, word) \
420 hbuf[0] = (unsigned char)(word); \
421 hbuf[1] = (unsigned char)((word) >> 8); \
422 hbuf[2] = (unsigned char)((word) >> 16); \
423 hbuf[3] = (unsigned char)((word) >> 24); \
424 check = crc32(check, hbuf, 4); \
431 put = strm->next_out; \
432 left = strm->avail_out; \
433 next = strm->next_in; \
434 have = strm->avail_in; \
435 hold = state->hold; \
436 bits = state->bits; \
442 strm->next_out = put; \
443 strm->avail_out = left; \
444 strm->next_in = next; \
445 strm->avail_in = have; \
446 state->hold = hold; \
447 state->bits = bits; \
461 if (have == 0) goto inf_leave; \
463 hold += (unsigned long)(*next++) << bits; \
469 #define NEEDBITS(n) \
471 while (bits < (unsigned)(n)) \
477 ((unsigned)hold & ((1U << (n)) - 1))
480 #define DROPBITS(n) \
483 bits -= (unsigned)(n); \
495 ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
496 (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
583 unsigned char FAR *
next;
584 unsigned char FAR *put;
590 unsigned char FAR *from;
596 unsigned char hbuf[4];
598 static const unsigned short order[19] =
599 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
602 (strm->next_in ==
Z_NULL && strm->avail_in != 0))
612 switch (state->
mode) {
614 if (state->
wrap == 0) {
620 if ((state->
wrap & 2) && hold == 0x8b1f) {
629 state->
head->done = -1;
630 if (!(state->
wrap & 1) ||
634 ((
BITS(8) << 8) + (hold >> 8)) % 31) {
635 strm->msg = (
char *)
"incorrect header check";
640 strm->msg = (
char *)
"unknown compression method";
646 if (state->
wbits == 0)
648 else if (len > state->
wbits) {
649 strm->msg = (
char *)
"invalid window size";
653 state->
dmax = 1U << len;
654 Tracev((stderr,
"inflate: zlib header ok\n"));
662 state->
flags = (int)(hold);
664 strm->msg = (
char *)
"unknown compression method";
668 if (state->
flags & 0xe000) {
669 strm->msg = (
char *)
"unknown header flags set";
674 state->
head->text = (int)((hold >> 8) & 1);
688 state->
head->xflags = (int)(hold & 0xff);
689 state->
head->os = (int)(hold >> 8);
695 if (state->
flags & 0x0400) {
697 state->
length = (unsigned)(hold);
699 state->
head->extra_len = (unsigned)hold;
707 if (state->
flags & 0x0400) {
709 if (copy > have) copy =
have;
715 len + copy > state->
head->extra_max ?
716 state->
head->extra_max - len : copy);
718 if (state->
flags & 0x0200)
724 if (state->
length)
goto inf_leave;
729 if (state->
flags & 0x0800) {
730 if (have == 0)
goto inf_leave;
733 len = (unsigned)(next[copy++]);
738 }
while (len && copy < have);
739 if (state->
flags & 0x0200)
743 if (len)
goto inf_leave;
750 if (state->
flags & 0x1000) {
751 if (have == 0)
goto inf_leave;
754 len = (unsigned)(next[copy++]);
759 }
while (len && copy < have);
760 if (state->
flags & 0x0200)
764 if (len)
goto inf_leave;
770 if (state->
flags & 0x0200) {
772 if (hold != (state->
check & 0xffff)) {
773 strm->msg = (
char *)
"header crc mismatch";
780 state->
head->hcrc = (int)((state->
flags >> 9) & 1);
781 state->
head->done = 1;
812 Tracev((stderr,
"inflate: stored block%s\n",
813 state->
last ?
" (last)" :
""));
818 Tracev((stderr,
"inflate: fixed codes block%s\n",
819 state->
last ?
" (last)" :
""));
827 Tracev((stderr,
"inflate: dynamic codes block%s\n",
828 state->
last ?
" (last)" :
""));
832 strm->msg = (
char *)
"invalid block type";
840 if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
841 strm->msg = (
char *)
"invalid stored block lengths";
845 state->
length = (unsigned)hold & 0xffff;
846 Tracev((stderr,
"inflate: stored length %u\n",
850 if (flush ==
Z_TREES)
goto inf_leave;
856 if (copy > have) copy =
have;
857 if (copy > left) copy = left;
858 if (copy == 0)
goto inf_leave;
867 Tracev((stderr,
"inflate: stored end\n"));
878 #ifndef PKZIP_BUG_WORKAROUND
879 if (state->
nlen > 286 || state->
ndist > 30) {
880 strm->msg = (
char *)
"too many length or distance symbols";
885 Tracev((stderr,
"inflate: table sizes ok\n"));
891 state->
lens[order[state->
have++]] = (
unsigned short)
BITS(3);
894 while (state->
have < 19)
895 state->
lens[order[state->
have++]] = 0;
902 strm->msg = (
char *)
"invalid code lengths set";
906 Tracev((stderr,
"inflate: code lengths ok\n"));
913 if ((
unsigned)(here.
bits) <= bits)
break;
922 if (here.
val == 16) {
925 if (state->
have == 0) {
926 strm->msg = (
char *)
"invalid bit length repeat";
934 else if (here.
val == 17) {
949 strm->msg = (
char *)
"invalid bit length repeat";
954 state->
lens[state->
have++] = (
unsigned short)len;
962 if (state->
lens[256] == 0) {
963 strm->msg = (
char *)
"invalid code -- missing end-of-block";
977 strm->msg = (
char *)
"invalid literal/lengths set";
986 strm->msg = (
char *)
"invalid distances set";
990 Tracev((stderr,
"inflate: codes ok\n"));
992 if (flush ==
Z_TREES)
goto inf_leave;
996 if (have >= 6 && left >= 258) {
1007 if ((
unsigned)(here.
bits) <= bits)
break;
1010 if (here.
op && (here.
op & 0xf0) == 0) {
1015 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1024 if ((
int)(here.
op) == 0) {
1026 "inflate: literal '%c'\n" :
1027 "inflate: literal 0x%02x\n", here.
val));
1032 Tracevv((stderr,
"inflate: end of block\n"));
1038 strm->msg = (
char *)
"invalid literal/length code";
1042 state->
extra = (unsigned)(here.
op) & 15;
1057 if ((
unsigned)(here.
bits) <= bits)
break;
1060 if ((here.
op & 0xf0) == 0) {
1065 if ((
unsigned)(last.
bits + here.
bits) <= bits)
break;
1074 strm->msg = (
char *)
"invalid distance code";
1079 state->
extra = (
unsigned)(here.
op) & 15;
1088 #ifdef INFLATE_STRICT
1090 strm->msg = (
char *)
"invalid distance too far back";
1098 if (left == 0)
goto inf_leave;
1100 if (state->
offset > copy) {
1102 if (copy > state->
whave) {
1104 strm->msg = (
char *)
"invalid distance too far back";
1108 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1109 Trace((stderr,
"inflate.c too far\n"));
1110 copy -= state->
whave;
1112 if (copy > left) copy = left;
1122 if (copy > state->
wnext) {
1123 copy -= state->
wnext;
1131 from = put - state->
offset;
1134 if (copy > left) copy = left;
1143 if (left == 0)
goto inf_leave;
1144 *put++ = (
unsigned char)(state->
length);
1152 strm->total_out += out;
1153 state->
total += out;
1155 strm->adler = state->
check =
1160 state->
flags ? hold :
1163 strm->msg = (
char *)
"incorrect data check";
1168 Tracev((stderr,
"inflate: check matches trailer\n"));
1175 if (hold != (state->
total & 0xffffffffUL)) {
1176 strm->msg = (
char *)
"incorrect length check";
1181 Tracev((stderr,
"inflate: length matches trailer\n"));
1206 if (state->
wsize || (state->
mode <
CHECK && out != strm->avail_out))
1211 in -= strm->avail_in;
1212 out -= strm->avail_out;
1213 strm->total_in += in;
1214 strm->total_out += out;
1215 state->
total += out;
1216 if (state->
wrap && out)
1217 strm->adler = state->
check =
1219 strm->data_type = state->
bits + (state->
last ? 64 : 0) +
1222 if (((in == 0 && out == 0) || flush ==
Z_FINISH) && ret ==
Z_OK)
1230 if (strm ==
Z_NULL || strm->state ==
Z_NULL || strm->zfree == (free_func)0)
1234 ZFREE(strm, strm->state);
1236 Tracev((stderr,
"inflate: end\n"));
1254 id =
adler32(
id, dictionary, dictLength);
1255 if (
id != state->
check)
1264 if (dictLength > state->
wsize) {
1272 state->
whave = dictLength;
1275 Tracev((stderr,
"inflate: dictionary set\n"));
1312 while (next < len && got < 4) {
1313 if ((
int)(buf[next]) == (got < 2 ? 0 : 0xff))
1328 unsigned long in, out;
1329 unsigned char buf[4];
1343 while (state->
bits >= 8) {
1344 buf[len++] = (
unsigned char)(state->
hold);
1354 strm->avail_in -= len;
1355 strm->next_in += len;
1356 strm->total_in += len;
1360 in = strm->total_in; out = strm->total_out;
1362 strm->total_in = in; strm->total_out = out;
1388 unsigned char FAR *
window;
1393 source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
1403 window = (
unsigned char FAR *)
1404 ZALLOC(source, 1U << state->
wbits,
sizeof(
unsigned char));
1406 ZFREE(source, copy);
1421 wsize = 1U << state->
wbits;
1435 state->
sane = !subvert;
1436 #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1448 if (strm ==
Z_NULL || strm->state ==
Z_NULL)
return -1L << 16;
1450 return ((
long)(state->
back) << 16) +
local unsigned syncsearch(unsigned FAR *have, unsigned char FAR *buf, unsigned len)
static void copy(const T &from, T &to)
int ZEXPORT inflateReset(z_streamp strm)
local void fixedtables(struct inflate_state FAR *state)
code const FAR * distcode
int ZEXPORT inflateInit_(z_streamp strm, const char *version, int stream_size)
static const code lenfix[512]
gz_header FAR * gz_headerp
int ZEXPORT inflateReset2(z_streamp strm, int windowBits)
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
int ZEXPORT inflateSyncPoint(z_streamp strm)
#define ZALLOC(strm, items, size)
void ZLIB_INTERNAL inflate_fast(z_streamp strm, unsigned start)
#define CRC2(check, word)
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short FAR *lens, unsigned codes, code FAR *FAR *table, unsigned FAR *bits, unsigned short FAR *work)
static const code distfix[32]
#define ZFREE(strm, addr)
local int updatewindow(z_streamp strm, unsigned out)
#define ABC_NAMESPACE_IMPL_END
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
#define UPDATE(check, buf, len)
int ZEXPORT inflateSync(z_streamp strm)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
int ZEXPORT inflateUndermine(z_streamp strm, int subvert)
int ZEXPORT inflateGetHeader(z_streamp strm, gz_headerp head)
#define ABC_NAMESPACE_IMPL_START
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
ABC_NAMESPACE_IMPL_START local void fixedtables OF((struct inflate_state FAR *state))
int ZEXPORT inflatePrime(z_streamp strm, int bits, int value)
long ZEXPORT inflateMark(z_streamp strm)
unsigned char FAR * window
int ZEXPORT inflate(z_streamp strm, int flush)
#define CRC4(check, word)
int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
static char * bits(int n)
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
int ZEXPORT inflateEnd(z_streamp strm)
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)