210typedef unsigned short ush;
218# define NEXTBYTE csz__ReadByte()
222# define FPRINTF fprintf
226# define FLUSH(n) csz__WriteData(n)
233# define Trace(x) fprintf x
268 struct huft **,
int *);
293static uch csz__slide [32768];
298static unsigned border[] = {
299 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
300static ush cplens[] = {
301 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
302 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
304static ush cplext[] = {
305 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
306 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99};
307static ush cpdist[] = {
308 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
309 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
310 8193, 12289, 16385, 24577};
311static ush cpdext[] = {
312 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
313 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
319 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
320 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
346static uch *ibufptr,*obufptr;
347static long ibufcnt, obufcnt;
352static int csz__ReadByte();
354static void csz__WriteData(
int);
357# define NEEDBITS(n) {while(k<(n)){b|=((ulg)NEXTBYTE)<<k;k+=8;}}
359# define NEEDBITS(n) {while(k<(n)){if(ibufcnt-- <= 0)return 1;b|=((ulg) *ibufptr++)<<k;k+=8;}}
362#define DUMPBITS(n) {b>>=(n);k-=(n);}
407static unsigned hufts;
452 el =
n > 256 ?
b[256] :
BMAX;
453 memset((
char *)c,0,
sizeof(c));
460 *
t = (
struct huft *)NULL;
467 for (j = 1; j <=
BMAX; j++)
471 if ((
unsigned)*m < j)
473 for (i =
BMAX; i; i--)
477 if ((
unsigned)*m > i)
482 for (y = 1 << j; j < i; j++, y <<= 1)
492 p = c + 1; xp = x + 2;
511 u[0] = (
struct huft *)NULL;
512 q = (
struct huft *)NULL;
528 z = (z = g - w) > (
unsigned)*m ? (unsigned) *m : z;
529 if ((f = 1 << (j = k - w)) > a + 1)
535 if ((f <<= 1) <= *++xp)
540 if ((
unsigned)w + j > el && (unsigned)w < el)
546 if ((q = (
struct huft *)malloc((z + 1)*
sizeof(
struct huft))) ==
555 *(
t = &(q->
v.
t)) = (
struct huft *)NULL;
565 j = (i & ((1 << w) - 1)) >> (w - l[h-1]);
575 r.
e = (
uch)(*p < 256 ? 16 : 15);
578 r.
e = (
uch)
e[*p - s];
584 for (j = i >> w; j < z; j += f)
588 for (j = 1 << (k - 1); i & j; j >>= 1)
593 while ((i & ((1 << w) - 1)) != x[h])
604 return y != 0 && g != 1;
620 while (p != (
struct huft *)NULL)
665 if ((
e = (
t = tl + ((
unsigned)
b & ml))->
e) > 16)
672 }
while ((
e = (
t =
t->
v.
t + ((
unsigned)
b & mask[
e]))->e) > 16);
676 csz__slide[w++] = (
uch)
t->
v.
n;
691 n =
t->
v.
n + ((unsigned)
b & mask[
e]);
696 if ((
e = (
t = td + ((
unsigned)
b & md))->
e) > 16)
703 }
while ((
e = (
t =
t->
v.
t + ((
unsigned)
b & mask[
e]))->e) > 16);
706 d = w -
t->
v.
n - ((unsigned)
b & mask[
e]);
715 memcpy(csz__slide + w, csz__slide + d,
e);
722 csz__slide[w++] = csz__slide[d++];
758 Trace((stderr,
"\nstored block"));
771 n = ((unsigned)
b & 0xffff);
774 if (
n != (
unsigned)((~
b) & 0xffff))
783 csz__slide[w++] = (
uch)
b;
812 Trace((stderr,
"\nliteral block"));
816 static unsigned l[288];
819 for (i = 0; i < 144; i++)
836 for (i = 0; i < 30; i++)
869#ifdef PKZIP_BUG_WORKAROUND
870 static unsigned ll[288+32];
872 static unsigned ll[286+30];
877 static int qflag = 0;
880 Trace((stderr,
"\ndynamic block"));
887 nl = 257 + ((unsigned)
b & 0x1f);
890 nd = 1 + ((unsigned)
b & 0x1f);
893 nb = 4 + ((unsigned)
b & 0xf);
895#ifdef PKZIP_BUG_WORKAROUND
896 if (nl > 288 || nd > 32)
898 if (nl > 286 || nd > 30)
904 for (j = 0; j < nb; j++)
907 ll[border[j]] = (unsigned)
b & 7;
924#define NEEDBITS_free_tl(n) {while(k<(n)){if(ibufcnt-- <= 0){csz__huft_free(tl);return 1;} b|=((ulg) *ibufptr++)<<k;k+=8;}}
930 while ((
unsigned)i <
n)
933 j = (td = tl + ((unsigned)
b & m))->
b;
941 j = 3 + ((unsigned)
b & 3);
943 if ((
unsigned)i + j >
n) {
953 j = 3 + ((unsigned)
b & 7);
955 if ((
unsigned)i + j >
n){
966 j = 11 + ((unsigned)
b & 0x7f);
968 if ((
unsigned)i + j >
n) {
992 if (i == 1 && !qflag) {
993 FPRINTF(stderr,
"(incomplete l-tree) ");
999 if ((i =
csz__huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0)
1001 if (i == 1 && !qflag) {
1002 FPRINTF(stderr,
"(incomplete d-tree) ");
1003#ifdef PKZIP_BUG_WORKAROUND
1050 t = (unsigned)
b & 3;
1106 Trace((stderr,
"\n%lu bytes in Huffman tables (%lu/entry)\n",
1107 h *
sizeof(
struct huft),
sizeof(
struct huft)));
1124 long a_obufcnt,
unsigned char* a_obufptr) {
1125 ibufcnt = a_ibufcnt;
1126 ibufptr = a_ibufptr;
1128 obufcnt = a_obufcnt;
1129 obufptr = a_obufptr;
1138static int csz__ReadByte ()
1149static void csz__WriteData(
int n)
1151 if( obufcnt >=
n ) memcpy(obufptr, csz__slide,
n);
int csz__Inflate_block(int *)
int csz__huft_build(unsigned *, unsigned, unsigned, ush *, ush *, struct huft **, int *)
int csz__Inflate_stored(void)
int csz__Inflate_fixed(void)
void csz__Init_Inflate(long a_ibufcnt, unsigned char *a_ibufptr, long a_obufcnt, unsigned char *a_obufptr)
#define NEEDBITS_free_tl(n)
struct huft * csz__fixed_tl
int csz__Inflate_codes(struct huft *, struct huft *, int, int)
int csz__Inflate_dynamic(void)
struct huft * csz__fixed_td
int csz__Inflate_free(void)
unsigned char * csz__obufptr()
int csz__huft_free(struct huft *)