jdk/src/share/native/java/util/zip/zlib-1.2.8/deflate.h
author sherman
Wed, 04 Jun 2014 11:25:13 -0700
changeset 24710 c019dc4104b2
permissions -rw-r--r--
8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files Summary: to upgrade zlib version from 1.2.5 to 1.2.8 Reviewed-by: alanb, iris
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24710
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     1
/*
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     3
 *
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
     9
 *
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    14
 * accompanied this code).
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    15
 *
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    19
 *
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    22
 * questions.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    23
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    24
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    25
/* deflate.h -- internal compression state
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    26
 * Copyright (C) 1995-2012 Jean-loup Gailly
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    27
 * For conditions of distribution and use, see copyright notice in zlib.h
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    28
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    29
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    30
/* WARNING: this file should *not* be used by applications. It is
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    31
   part of the implementation of the compression library and is
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    32
   subject to change. Applications should only use zlib.h.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    33
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    34
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    35
/* @(#) $Id$ */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    36
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    37
#ifndef DEFLATE_H
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    38
#define DEFLATE_H
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    39
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    40
#include "zutil.h"
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    41
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    42
/* define NO_GZIP when compiling if you want to disable gzip header and
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    43
   trailer creation by deflate().  NO_GZIP would be used to avoid linking in
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    44
   the crc code when it is not needed.  For shared libraries, gzip encoding
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    45
   should be left enabled. */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    46
#ifndef NO_GZIP
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    47
#  define GZIP
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    48
#endif
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    49
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    50
/* ===========================================================================
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    51
 * Internal compression state.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    52
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    53
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    54
#define LENGTH_CODES 29
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    55
/* number of length codes, not counting the special END_BLOCK code */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    56
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    57
#define LITERALS  256
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    58
/* number of literal bytes 0..255 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    59
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    60
#define L_CODES (LITERALS+1+LENGTH_CODES)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    61
/* number of Literal or Length codes, including the END_BLOCK code */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    62
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    63
#define D_CODES   30
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    64
/* number of distance codes */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    65
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    66
#define BL_CODES  19
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    67
/* number of codes used to transfer the bit lengths */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    68
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    69
#define HEAP_SIZE (2*L_CODES+1)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    70
/* maximum heap size */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    71
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    72
#define MAX_BITS 15
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    73
/* All codes must not exceed MAX_BITS bits */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    74
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    75
#define Buf_size 16
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    76
/* size of bit buffer in bi_buf */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    77
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    78
#define INIT_STATE    42
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    79
#define EXTRA_STATE   69
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    80
#define NAME_STATE    73
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    81
#define COMMENT_STATE 91
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    82
#define HCRC_STATE   103
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    83
#define BUSY_STATE   113
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    84
#define FINISH_STATE 666
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    85
/* Stream status */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    86
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    87
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    88
/* Data structure describing a single value and its code string. */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    89
typedef struct ct_data_s {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    90
    union {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    91
        ush  freq;       /* frequency count */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    92
        ush  code;       /* bit string */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    93
    } fc;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    94
    union {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    95
        ush  dad;        /* father node in Huffman tree */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    96
        ush  len;        /* length of bit string */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    97
    } dl;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    98
} FAR ct_data;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
    99
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   100
#define Freq fc.freq
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   101
#define Code fc.code
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   102
#define Dad  dl.dad
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   103
#define Len  dl.len
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   104
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   105
typedef struct static_tree_desc_s  static_tree_desc;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   106
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   107
typedef struct tree_desc_s {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   108
    ct_data *dyn_tree;           /* the dynamic tree */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   109
    int     max_code;            /* largest code with non zero frequency */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   110
    static_tree_desc *stat_desc; /* the corresponding static tree */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   111
} FAR tree_desc;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   112
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   113
typedef ush Pos;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   114
typedef Pos FAR Posf;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   115
typedef unsigned IPos;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   116
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   117
/* A Pos is an index in the character window. We use short instead of int to
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   118
 * save space in the various tables. IPos is used only for parameter passing.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   119
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   120
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   121
typedef struct internal_state {
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   122
    z_streamp strm;      /* pointer back to this zlib stream */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   123
    int   status;        /* as the name implies */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   124
    Bytef *pending_buf;  /* output still pending */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   125
    ulg   pending_buf_size; /* size of pending_buf */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   126
    Bytef *pending_out;  /* next pending byte to output to the stream */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   127
    uInt   pending;      /* nb of bytes in the pending buffer */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   128
    int   wrap;          /* bit 0 true for zlib, bit 1 true for gzip */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   129
    gz_headerp  gzhead;  /* gzip header information to write */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   130
    uInt   gzindex;      /* where in extra, name, or comment */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   131
    Byte  method;        /* can only be DEFLATED */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   132
    int   last_flush;    /* value of flush param for previous deflate call */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   133
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   134
                /* used by deflate.c: */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   135
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   136
    uInt  w_size;        /* LZ77 window size (32K by default) */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   137
    uInt  w_bits;        /* log2(w_size)  (8..16) */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   138
    uInt  w_mask;        /* w_size - 1 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   139
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   140
    Bytef *window;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   141
    /* Sliding window. Input bytes are read into the second half of the window,
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   142
     * and move to the first half later to keep a dictionary of at least wSize
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   143
     * bytes. With this organization, matches are limited to a distance of
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   144
     * wSize-MAX_MATCH bytes, but this ensures that IO is always
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   145
     * performed with a length multiple of the block size. Also, it limits
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   146
     * the window size to 64K, which is quite useful on MSDOS.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   147
     * To do: use the user input buffer as sliding window.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   148
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   149
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   150
    ulg window_size;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   151
    /* Actual size of window: 2*wSize, except when the user input buffer
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   152
     * is directly used as sliding window.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   153
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   154
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   155
    Posf *prev;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   156
    /* Link to older string with same hash index. To limit the size of this
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   157
     * array to 64K, this link is maintained only for the last 32K strings.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   158
     * An index in this array is thus a window index modulo 32K.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   159
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   160
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   161
    Posf *head; /* Heads of the hash chains or NIL. */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   162
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   163
    uInt  ins_h;          /* hash index of string to be inserted */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   164
    uInt  hash_size;      /* number of elements in hash table */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   165
    uInt  hash_bits;      /* log2(hash_size) */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   166
    uInt  hash_mask;      /* hash_size-1 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   167
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   168
    uInt  hash_shift;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   169
    /* Number of bits by which ins_h must be shifted at each input
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   170
     * step. It must be such that after MIN_MATCH steps, the oldest
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   171
     * byte no longer takes part in the hash key, that is:
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   172
     *   hash_shift * MIN_MATCH >= hash_bits
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   173
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   174
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   175
    long block_start;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   176
    /* Window position at the beginning of the current output block. Gets
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   177
     * negative when the window is moved backwards.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   178
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   179
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   180
    uInt match_length;           /* length of best match */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   181
    IPos prev_match;             /* previous match */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   182
    int match_available;         /* set if previous match exists */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   183
    uInt strstart;               /* start of string to insert */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   184
    uInt match_start;            /* start of matching string */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   185
    uInt lookahead;              /* number of valid bytes ahead in window */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   186
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   187
    uInt prev_length;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   188
    /* Length of the best match at previous step. Matches not greater than this
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   189
     * are discarded. This is used in the lazy match evaluation.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   190
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   191
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   192
    uInt max_chain_length;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   193
    /* To speed up deflation, hash chains are never searched beyond this
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   194
     * length.  A higher limit improves compression ratio but degrades the
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   195
     * speed.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   196
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   197
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   198
    uInt max_lazy_match;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   199
    /* Attempt to find a better match only when the current match is strictly
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   200
     * smaller than this value. This mechanism is used only for compression
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   201
     * levels >= 4.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   202
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   203
#   define max_insert_length  max_lazy_match
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   204
    /* Insert new strings in the hash table only if the match length is not
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   205
     * greater than this length. This saves time but degrades compression.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   206
     * max_insert_length is used only for compression levels <= 3.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   207
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   208
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   209
    int level;    /* compression level (1..9) */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   210
    int strategy; /* favor or force Huffman coding*/
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   211
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   212
    uInt good_match;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   213
    /* Use a faster search when the previous match is longer than this */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   214
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   215
    int nice_match; /* Stop searching when current match exceeds this */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   216
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   217
                /* used by trees.c: */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   218
    /* Didn't use ct_data typedef below to suppress compiler warning */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   219
    struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   220
    struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   221
    struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   222
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   223
    struct tree_desc_s l_desc;               /* desc. for literal tree */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   224
    struct tree_desc_s d_desc;               /* desc. for distance tree */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   225
    struct tree_desc_s bl_desc;              /* desc. for bit length tree */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   226
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   227
    ush bl_count[MAX_BITS+1];
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   228
    /* number of codes at each bit length for an optimal tree */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   229
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   230
    int heap[2*L_CODES+1];      /* heap used to build the Huffman trees */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   231
    int heap_len;               /* number of elements in the heap */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   232
    int heap_max;               /* element of largest frequency */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   233
    /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   234
     * The same heap array is used to build all trees.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   235
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   236
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   237
    uch depth[2*L_CODES+1];
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   238
    /* Depth of each subtree used as tie breaker for trees of equal frequency
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   239
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   240
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   241
    uchf *l_buf;          /* buffer for literals or lengths */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   242
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   243
    uInt  lit_bufsize;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   244
    /* Size of match buffer for literals/lengths.  There are 4 reasons for
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   245
     * limiting lit_bufsize to 64K:
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   246
     *   - frequencies can be kept in 16 bit counters
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   247
     *   - if compression is not successful for the first block, all input
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   248
     *     data is still in the window so we can still emit a stored block even
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   249
     *     when input comes from standard input.  (This can also be done for
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   250
     *     all blocks if lit_bufsize is not greater than 32K.)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   251
     *   - if compression is not successful for a file smaller than 64K, we can
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   252
     *     even emit a stored file instead of a stored block (saving 5 bytes).
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   253
     *     This is applicable only for zip (not gzip or zlib).
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   254
     *   - creating new Huffman trees less frequently may not provide fast
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   255
     *     adaptation to changes in the input data statistics. (Take for
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   256
     *     example a binary file with poorly compressible code followed by
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   257
     *     a highly compressible string table.) Smaller buffer sizes give
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   258
     *     fast adaptation but have of course the overhead of transmitting
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   259
     *     trees more frequently.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   260
     *   - I can't count above 4
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   261
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   262
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   263
    uInt last_lit;      /* running index in l_buf */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   264
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   265
    ushf *d_buf;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   266
    /* Buffer for distances. To simplify the code, d_buf and l_buf have
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   267
     * the same number of elements. To use different lengths, an extra flag
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   268
     * array would be necessary.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   269
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   270
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   271
    ulg opt_len;        /* bit length of current block with optimal trees */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   272
    ulg static_len;     /* bit length of current block with static trees */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   273
    uInt matches;       /* number of string matches in current block */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   274
    uInt insert;        /* bytes at end of window left to insert */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   275
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   276
#ifdef DEBUG
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   277
    ulg compressed_len; /* total bit length of compressed file mod 2^32 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   278
    ulg bits_sent;      /* bit length of compressed data sent mod 2^32 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   279
#endif
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   280
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   281
    ush bi_buf;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   282
    /* Output buffer. bits are inserted starting at the bottom (least
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   283
     * significant bits).
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   284
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   285
    int bi_valid;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   286
    /* Number of valid bits in bi_buf.  All bits above the last valid bit
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   287
     * are always zero.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   288
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   289
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   290
    ulg high_water;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   291
    /* High water mark offset in window for initialized bytes -- bytes above
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   292
     * this are set to zero in order to avoid memory check warnings when
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   293
     * longest match routines access bytes past the input.  This is then
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   294
     * updated to the new high water mark.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   295
     */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   296
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   297
} FAR deflate_state;
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   298
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   299
/* Output a byte on the stream.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   300
 * IN assertion: there is enough room in pending_buf.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   301
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   302
#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   303
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   304
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   305
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   306
/* Minimum amount of lookahead, except at the end of the input file.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   307
 * See deflate.c for comments about the MIN_MATCH+1.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   308
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   309
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   310
#define MAX_DIST(s)  ((s)->w_size-MIN_LOOKAHEAD)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   311
/* In order to simplify the code, particularly on 16 bit machines, match
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   312
 * distances are limited to MAX_DIST instead of WSIZE.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   313
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   314
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   315
#define WIN_INIT MAX_MATCH
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   316
/* Number of bytes after end of data in window to initialize in order to avoid
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   317
   memory checker errors from longest match routines */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   318
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   319
        /* in trees.c */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   320
void ZLIB_INTERNAL _tr_init OF((deflate_state *s));
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   321
int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   322
void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf,
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   323
                        ulg stored_len, int last));
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   324
void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s));
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   325
void ZLIB_INTERNAL _tr_align OF((deflate_state *s));
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   326
void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf,
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   327
                        ulg stored_len, int last));
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   328
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   329
#define d_code(dist) \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   330
   ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   331
/* Mapping from a distance to a distance code. dist is the distance - 1 and
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   332
 * must not have side effects. _dist_code[256] and _dist_code[257] are never
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   333
 * used.
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   334
 */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   335
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   336
#ifndef DEBUG
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   337
/* Inline versions of _tr_tally for speed: */
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   338
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   339
#if defined(GEN_TREES_H) || !defined(STDC)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   340
  extern uch ZLIB_INTERNAL _length_code[];
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   341
  extern uch ZLIB_INTERNAL _dist_code[];
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   342
#else
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   343
  extern const uch ZLIB_INTERNAL _length_code[];
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   344
  extern const uch ZLIB_INTERNAL _dist_code[];
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   345
#endif
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   346
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   347
# define _tr_tally_lit(s, c, flush) \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   348
  { uch cc = (c); \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   349
    s->d_buf[s->last_lit] = 0; \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   350
    s->l_buf[s->last_lit++] = cc; \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   351
    s->dyn_ltree[cc].Freq++; \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   352
    flush = (s->last_lit == s->lit_bufsize-1); \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   353
   }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   354
# define _tr_tally_dist(s, distance, length, flush) \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   355
  { uch len = (length); \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   356
    ush dist = (distance); \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   357
    s->d_buf[s->last_lit] = dist; \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   358
    s->l_buf[s->last_lit++] = len; \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   359
    dist--; \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   360
    s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   361
    s->dyn_dtree[d_code(dist)].Freq++; \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   362
    flush = (s->last_lit == s->lit_bufsize-1); \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   363
  }
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   364
#else
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   365
# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   366
# define _tr_tally_dist(s, distance, length, flush) \
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   367
              flush = _tr_tally(s, distance, length)
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   368
#endif
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   369
c019dc4104b2 8044725: Bug in zlib 1.2.5 prevents inflation of some gzipped files
sherman
parents:
diff changeset
   370
#endif /* DEFLATE_H */