infutil.c
上传用户:zlh9724
上传日期:2007-01-04
资源大小:1991k
文件大小:2k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. /* inflate_util.c -- data and routines common to blocks and codes
  2.  * Copyright (C) 1995 Mark Adler
  3.  * For conditions of distribution and use, see copyright notice in zlib.h 
  4.  */
  5. #include "zutil.h"
  6. #include "infblock.h"
  7. #include "inftrees.h"
  8. #include "infcodes.h"
  9. #include "infutil.h"
  10. struct inflate_codes_state {int dummy;}; /* for buggy compilers */
  11. /* And'ing with mask[n] masks the lower n bits */
  12. uInt inflate_mask[] = {
  13.     0x0000,
  14.     0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
  15.     0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
  16. };
  17. /* copy as much as possible from the sliding window to the output area */
  18. int inflate_flush(s, z, r)
  19. inflate_blocks_statef *s;
  20. z_stream *z;
  21. int r;
  22. {
  23.   uInt n;
  24.   Bytef *p, *q;
  25.   /* local copies of source and destination pointers */
  26.   p = z->next_out;
  27.   q = s->read;
  28.   /* compute number of bytes to copy as far as end of window */
  29.   n = (uInt)((q <= s->write ? s->write : s->end) - q);
  30.   if (n > z->avail_out) n = z->avail_out;
  31.   if (n && r == Z_BUF_ERROR) r = Z_OK;
  32.   /* update counters */
  33.   z->avail_out -= n;
  34.   z->total_out += n;
  35.   /* update check information */
  36.   if (s->checkfn != Z_NULL)
  37.     s->check = (*s->checkfn)(s->check, q, n);
  38.   /* copy as far as end of window */
  39.   zmemcpy(p, q, n);
  40.   p += n;
  41.   q += n;
  42.   /* see if more to copy at beginning of window */
  43.   if (q == s->end)
  44.   {
  45.     /* wrap pointers */
  46.     q = s->window;
  47.     if (s->write == s->end)
  48.       s->write = s->window;
  49.     /* compute bytes to copy */
  50.     n = (uInt)(s->write - q);
  51.     if (n > z->avail_out) n = z->avail_out;
  52.     if (n && r == Z_BUF_ERROR) r = Z_OK;
  53.     /* update counters */
  54.     z->avail_out -= n;
  55.     z->total_out += n;
  56.     /* update check information */
  57.     if (s->checkfn != Z_NULL)
  58.       s->check = (*s->checkfn)(s->check, q, n);
  59.     /* copy */
  60.     zmemcpy(p, q, n);
  61.     p += n;
  62.     q += n;
  63.   }
  64.   /* update pointers */
  65.   z->next_out = p;
  66.   s->read = q;
  67.   /* done */
  68.   return r;
  69. }