📄 inflate.c
字号:
r.v.n = d[*p++ - s]; }DEBUG_ZIP("h6d "); /* fill code-like entries with r */ f = 1 << (k - w); for (j = i >> w; j < z; j += f) q[j] = r; /* backwards increment the k-bit code i */ for (j = 1 << (k - 1); i & j; j >>= 1) i ^= j; i ^= j; /* backup over finished tables */ while ((i & ((1 << w) - 1)) != x[h]) { h--; /* don't need to update q */ w -= l; }DEBUG_ZIP("h6e "); }DEBUG_ZIP("h6f "); }DEBUG_ZIP("huft7 ");DEBUG_ZIP("(y,g) = (%d,%d)\n",y,g); /* Return true (1) if we were given an incomplete table */ return y != 0 && g != 1;}/****************************************************************************//* FUNCTION *//* *//* huft_free *//* *//* DESCRIPTION *//* Free the malloc'ed tables built by huft_build(), which *//* makes a linked list of the tables it mode, with the links in a dummy *//* first entry of each table. *//* *//* CALLED BY *//* *//* CALLS *//* *//* INPUTS *//* *//* *//* OUTPUTS *//* *//* STATUS *//* *//* HISTORY *//* *//* NAME DATE REMARKS *//* *//* yskim 20-06-2000 Created initial version 1.0 *//* *//****************************************************************************/static int huft_free(t)struct huft *t; /* table to free */{ register struct huft *p, *q; /* Go through linked list, freeing from the malloced (t[-1]) address. */ p = t; DEBUG_ZIP("huft_free(t): p = t = %d\n",(int)t); while (p != (struct huft *)NULL) { q = (--p)->v.t; DEBUG_ZIP("huft_free(t): q = %d\n",(int)q); free((char*)p); p = q; DEBUG_ZIP("huft_free(t): p = q = %d\n",(int)p); } return 0;}/****************************************************************************//* FUNCTION *//* *//* inflate_codes *//* *//* DESCRIPTION *//* inflate (decompress) the codes in a deflated (compressed) *//* block. Return an error code or zero if it all goes ok. *//* *//* CALLED BY *//* *//* CALLS *//* *//* INPUTS *//* *//* *//* OUTPUTS *//* *//* STATUS *//* *//* HISTORY *//* *//* NAME DATE REMARKS *//* *//* yskim 20-06-2000 Created initial version 1.0 *//* *//****************************************************************************/static int inflate_codes(tl, td, bl, bd)struct huft *tl, *td; /* literal/length and distance decoder tables */int bl, bd; /* number of bits decoded by tl[] and td[] */{ register unsigned e; /* table entry flag/number of extra bits */ unsigned n, d; /* length and index for copy */ unsigned w; /* current window position */ struct huft *t; /* pointer to table entry */ unsigned ml, md; /* masks for bl and bd bits */ register u32 b; /* bit buffer */ register unsigned k; /* number of bits in bit buffer */ /* make local copies of globals */ b = bb; /* initialize bit buffer */ k = bk; w = wp; /* initialize window position */ /* inflate the coded data */ ml = mask_bits[bl]; /* precompute masks for speed */ md = mask_bits[bd]; for (;;) /* do until end of block */ { NEEDBITS((unsigned)bl) if ((e = (t = tl + ((unsigned)b & ml))->e) > 16) do { if (e == 99) return 1; DUMPBITS(t->b) e -= 16; NEEDBITS(e) } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16); DUMPBITS(t->b) if (e == 16) /* then it's a literal */ { slide[w++] = (u8)t->v.n; Tracevv((stderr, "%c", slide[w-1])); if (w == WSIZE) { flush_output(w); w = 0; } } else /* it's an EOB or a length */ { /* exit if end of block */ if (e == 15) break; /* get length of block to copy */ NEEDBITS(e) n = t->v.n + ((unsigned)b & mask_bits[e]); DUMPBITS(e); /* decode distance of block to copy */ NEEDBITS((unsigned)bd) if ((e = (t = td + ((unsigned)b & md))->e) > 16) do { if (e == 99) return 1; DUMPBITS(t->b) e -= 16; NEEDBITS(e) } while ((e = (t = t->v.t + ((unsigned)b & mask_bits[e]))->e) > 16); DUMPBITS(t->b) NEEDBITS(e) d = w - t->v.n - ((unsigned)b & mask_bits[e]); DUMPBITS(e) Tracevv((stderr,"\\[%d,%d]", w-d, n)); /* do the copy */ do { n -= (e = (e = WSIZE - ((d &= WSIZE-1) > w ? d : w)) > n ? n : e);#if !defined(NOMEMCPY) && !defined(DEBUG) if (w - d >= e) /* (this test assumes unsigned comparison) */ { memcpy(slide + w, slide + d, e); w += e; d += e; } else /* do it slow to avoid memcpy() overlap */#endif /* !NOMEMCPY */ do { slide[w++] = slide[d++]; Tracevv((stderr, "%c", slide[w-1])); } while (--e); if (w == WSIZE) { flush_output(w); w = 0; } } while (n); } } /* restore the globals from the locals */ wp = w; /* restore global window pointer */ bb = b; /* restore global bit buffer */ bk = k; /* done */ return 0;}/****************************************************************************//* FUNCTION *//* *//* inflate_stored *//* *//* DESCRIPTION *//* "decompress" an inflated type 0 (stored) block. *//* *//* CALLED BY *//* *//* CALLS *//* *//* INPUTS *//* *//* *//* OUTPUTS *//* *//* STATUS *//* *//* HISTORY *//* *//* NAME DATE REMARKS *//* *//* yskim 20-06-2000 Created initial version 1.0 *//* *//****************************************************************************/static int inflate_stored(){ unsigned n; /* number of bytes in block */ unsigned w; /* current window position */ register u32 b; /* bit buffer */ register unsigned k; /* number of bits in bit buffer */DEBUG_ZIP("<store "); /* make local copies of globals */ b = bb; /* initialize bit buffer */ k = bk; w = wp; /* initialize window position */ /* go to byte boundary */ n = k & 7; DUMPBITS(n); /* get the length and its complement */ NEEDBITS(16) n = ((unsigned)b & 0xffff); DUMPBITS(16) NEEDBITS(16) if (n != (unsigned)((~b) & 0xffff)) return 1; /* error in compressed data */ DUMPBITS(16) /* read and output the compressed data */ while (n--) { NEEDBITS(8) slide[w++] = (u8)b; if (w == WSIZE) { flush_output(w); w = 0; } DUMPBITS(8) } /* restore the globals from the locals */ wp = w; /* restore global window pointer */ bb = b; /* restore global bit buffer */ bk = k; DEBUG_ZIP("> "); return 0;}/****************************************************************************//* FUNCTION *//* *//* inflate_fixed *//* *//* DESCRIPTION *//* decompress an inflated type 1 (fixed Huffman codes) block. *//* either replace this with a custom decoder, or at least precompute the *//* Huffman tables. *//* *//* CALLED BY *//* *//* CALLS *//* *//* INPUTS *//* *//* *//* OUTPUTS *//* *//* STATUS *//* *//* HISTORY *//* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -