224 typedef unsigned char uch;
225 typedef unsigned short ush;
226 typedef unsigned long ulg;
229 # define WSIZE 0x8000
233 # define NEXTBYTE csz__ReadByte()
237 # define FPRINTF fprintf
241 # define FLUSH(n) csz__WriteData(n)
248 # define Trace(x) fprintf x
283 struct huft **,
int *);
314 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
316 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
317 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
320 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
321 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99};
323 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
324 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
325 8193, 12289, 16385, 24577};
327 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
328 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
334 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
335 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
367 static int csz__ReadByte();
372 # define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE)<<k;k+=8;}}
374 # define NEEDBITS(n) {while(k<(n)){if(ibufcnt-- <= 0)return 1;b|=((ulg) *ibufptr++)<<k;k+=8;}}
377 #define DUMPBITS(n) {b>>=(n);k-=(n);}
467 el = n > 256 ? b[256] :
BMAX;
468 memset((
char *)c,0,
sizeof(c));
475 *t = (
struct huft *)NULL;
482 for (j = 1; j <=
BMAX; j++)
486 if ((
unsigned)*m < j)
488 for (i =
BMAX; i; i--)
492 if ((
unsigned)*m > i)
497 for (y = 1 << j; j < i; j++, y <<= 1)
507 p = c + 1; xp = x + 2;
526 u[0] = (
struct huft *)NULL;
527 q = (
struct huft *)NULL;
543 z = (z = g - w) > (
unsigned)*m ? (unsigned) *m : z;
544 if ((f = 1 << (j = k - w)) > a + 1)
550 if ((f <<= 1) <= *++xp)
555 if ((
unsigned)w + j > el && (unsigned)w < el)
561 if ((q = (
struct huft *)malloc((z + 1)*
sizeof(
struct huft))) ==
570 *(t = &(q->
v.
t)) = (
struct huft *)NULL;
580 j = (i & ((1 << w) - 1)) >> (w - l[h-1]);
590 r.
e = (
uch)(*p < 256 ? 16 : 15);
593 r.
e = (
uch)e[*p - s];
599 for (j = i >> w; j <
z; j += f)
603 for (j = 1 << (k - 1); i & j; j >>= 1)
608 while ((i & ((1 << w) - 1)) != x[h])
619 return y != 0 && g != 1;
635 while (p != (
struct huft *)NULL)
680 if ((e = (t = tl + ((
unsigned)b & ml))->e) > 16)
687 }
while ((e = (t = t->
v.
t + ((
unsigned)b &
mask[e]))->e) > 16);
706 n = t->
v.
n + ((unsigned)b &
mask[e]);
711 if ((e = (t = td + ((
unsigned)b & md))->e) > 16)
718 }
while ((e = (t = t->
v.
t + ((
unsigned)b &
mask[e]))->e) > 16);
721 d = w - t->
v.
n - ((unsigned)b &
mask[e]);
726 n -= (e = (e =
WSIZE - ((d &=
WSIZE-1) > w ? d : w)) > n ? n : e);
773 Trace((stderr,
"\nstored block"));
786 n = ((unsigned)b & 0xffff);
789 if (n != (
unsigned)((~b) & 0xffff))
827 Trace((stderr,
"\nliteral block"));
828 if (csz__fixed_tl == (
struct huft *)NULL)
831 static unsigned l[288];
834 for (i = 0; i < 144; i++)
846 csz__fixed_tl = (
struct huft *)NULL;
851 for (i = 0; i < 30; i++)
857 csz__fixed_tl = (
struct huft *)NULL;
884 #ifdef PKZIP_BUG_WORKAROUND
885 static unsigned ll[288+32];
887 static unsigned ll[286+30];
892 static int qflag = 0;
895 Trace((stderr,
"\ndynamic block"));
902 nl = 257 + ((unsigned)b & 0x1f);
905 nd = 1 + ((unsigned)b & 0x1f);
908 nb = 4 + ((unsigned)b & 0xf);
910 #ifdef PKZIP_BUG_WORKAROUND
911 if (nl > 288 || nd > 32)
913 if (nl > 286 || nd > 30)
919 for (j = 0; j < nb; j++)
922 ll[
border[j]] = (unsigned)b & 7;
939 #define NEEDBITS_free_tl(n) {while(k<(n)){if(ibufcnt-- <= 0){csz__huft_free(tl);return 1;} b|=((ulg) *ibufptr++)<<k;k+=8;}}
945 while ((
unsigned)i < n)
948 j = (td = tl + ((unsigned)b & m))->b;
956 j = 3 + ((unsigned)b & 3);
958 if ((
unsigned)i + j > n) {
968 j = 3 + ((unsigned)b & 7);
970 if ((
unsigned)i + j > n){
981 j = 11 + ((unsigned)b & 0x7f);
983 if ((
unsigned)i + j > n) {
1007 if (i == 1 && !qflag) {
1008 FPRINTF(stderr,
"(incomplete l-tree) ");
1016 if (i == 1 && !qflag) {
1017 FPRINTF(stderr,
"(incomplete d-tree) ");
1018 #ifdef PKZIP_BUG_WORKAROUND
1065 t = (unsigned)b & 3;
1121 Trace((stderr,
"\n%lu bytes in Huffman tables (%lu/entry)\n",
1122 h *
sizeof(
struct huft),
sizeof(
struct huft)));
1128 if (csz__fixed_tl != (
struct huft *)NULL)
1132 csz__fixed_td = csz__fixed_tl = (
struct huft *)NULL;
1139 long a_obufcnt,
unsigned char* a_obufptr) {
1153 static int csz__ReadByte ()
struct huft * csz__fixed_td
struct huft * csz__fixed_tl
int csz__Inflate_free(void)
int csz__Inflate_codes(struct huft *, struct huft *, int, int)
void csz__Init_Inflate(long a_ibufcnt, unsigned char *a_ibufptr, long a_obufcnt, unsigned char *a_obufptr)
#define NEEDBITS_free_tl(n)
static uch csz__slide[32768]
int csz__Inflate_dynamic(void)
int csz__Inflate_block(int *)
int csz__Inflate_fixed(void)
int csz__huft_build(unsigned *, unsigned, unsigned, ush *, ush *, struct huft **, int *)
unsigned char * csz__obufptr()
static void csz__WriteData(int)
int csz__Inflate_stored(void)
int csz__huft_free(struct huft *)